问题
I'm testing Activity Recognition API in 2 apps : Google sample code and implementation of this code in my app.
The problem is both apps keeps getting activity recognition fine but after a few hours the intent service stops and i'm not getting any activity recognition from both of them.
Any idea why the intent service stops even though i've tested geofencing api with intent service and it's working forever without stopping?
回答1:
Your IntentService might "stop", I would say "fall asleep" because of:
To conserve battery, activity reporting may stop when the device is 'STILL' for an extended period of time. It will resume once the device moves again. This only happens on devices that support the Sensor.TYPE_SIGNIFICANT_MOTION hardware.
Basically it should be the case for most of the devices with API >= 20.
Please find more here.
Unfortunately, you can only request activity updates and it is impossible to force ActivityRecognitionApi to continuously give current activity even if it is "still" for some mysterious "extended period of time".
In my opinion, it would much more convenient if this feature of ActivityRecognitionApi was configurable.
来源:https://stackoverflow.com/questions/29975230/activity-recognition-api-does-not-work-continuously