4

I was working on google's activity recognition and finally I got results from this service.

However, The function requestActivityUpdates(long detectionIntervalMillis, PendingIntent callbackIntent) doesn't seem to work correctly. The detection interval is not regular and decreases to 30~50 seconds when my current activity is changing. It doesn't work like the live demo on google I/O 2013 (Google I/O 2013 Location API, from 27:47 to 28:45). Does anyone have same issue on it?

DeVVil
  • 41
  • 3
  • I'm experiencing this issue right now, activity updates are delivered slower than ``detectionIntervalMillis``, especially when activity is changing, even if I set ``detectionIntervalMillis = 0`` – dragoon May 20 '15 at 18:14

2 Answers2

2

Well it's a bit confusing but the variable long detectionIntervalMillis does not fix the interval - it sets the maximum interval between two updates.

As it's said in the official documentation:

Activities may be received more frequently than the detectionIntervalMillis parameter if another application has also requested activity updates at a faster rate. It may also receive updates faster when the activity detection service receives a signal that the current activity may change, such as if the device has been still for a long period of time and is then unplugged from a phone charger.

Documentation

CodeShane
  • 6,480
  • 1
  • 18
  • 24
Piotr
  • 238
  • 2
  • 12
0

Instead of adding the build() part on onCreate directly try adding the method below and call it on onCreate(). And try to trace the code from google sample I got the code stripped down from that sample.

protected synchronized void buildGoogleApiClient() {
    mGoogleApiClient = new GoogleApiClient.Builder(this)
            .addConnectionCallbacks(this)
            .addOnConnectionFailedListener(this)
            .addApi(ActivityRecognition.API)
            .build();
}

and add buildGoogleApiClient() to your onCreate method ;) this works great for me!

ponnex
  • 838
  • 5
  • 18