Activity Recognition PendingIntent stop been called in the middle of the night

眉间皱痕 提交于 2019-12-18 17:34:36

问题


my application collects periodically Activity Recognition's Detected activity data. I implemented it exactly as described in the documentation , but with one minute interval.

as long as the user is logged in - the application registered with a PendingIntent to receive updates from google play process..

please not lecture me about battery usage, network, and performance problem derived from request updates each minute, unless it have something to do with my problem:

the problem: in some devices (in Nexus 5 it happens the most), for a 5-6 hours in the middle of the night - the IntentService stopped been called.

I'm not sure, but suspects it have something to do with Google optimizations and the significant motion sensor not detecting any motion entering the activity recognition mechanism to be in sort of idle mode, as described in the documentation that can happened.

it's important to my app to know what is the current activity each minute approximately even if it stay the same, or idle for a long time..

my question:

  • how can I know if the periodically activity recognition stopped been called because of the significant motion sensor or from any other reason?
  • it there a way to force somehow the Google play process to perform activity updates without stop it for a time it assumes not needed?

回答1:


Per ActivityRecognitionClient.requestActivityUpdates:

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.

As you suspected. There's no reason you cannot save the last value using the many data storage techniques - a simple SharedPreference might be enough for your case.

If you are directly triggering actions based on the IntentService being called (a bad idea since other apps may cause it to trigger extremely quickly) rather than only on changes in activity, then you should decouple those actions and instead set an alarm or trigger a periodic sync adapter for whatever specific time interval you need, reading the current value from the last activity you received.



来源:https://stackoverflow.com/questions/24177858/activity-recognition-pendingintent-stop-been-called-in-the-middle-of-the-night

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!