3

我的应用程序定期收集活动识别的检测到的活动数据。我完全按照文档中的描述实现了它,但间隔一分钟。

只要用户登录 - 注册的应用程序PendingIntent从谷歌播放进程接收更新..

请不要跟我讲每分钟更新请求导致的电池使用、网络和性能问题,除非它与我的问题有关:

问题: 在某些设备中(在 Nexus 5 中发生最多),在半夜持续 5-6 小时 - IntentService停止被调用。

我不确定,但怀疑它与 Google 优化有关,并且重要的运动传感器没有检测到任何进入活动识别机制的运动处于空闲模式,如可能发生的文档中所述。

对我的应用程序来说,了解每分钟大约的当前活动是什么很重要,即使它保持不变或闲置了很长时间..

我的问题:

  • 我怎么知道是否由于重要的运动传感器或任何其他原因而停止调用周期性活动识别?
  • 有没有办法以某种方式强制 Google Play 进程执行活动更新而不停止它假定不需要的时间?
4

1 回答 1

4

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.

于 2014-06-12T06:41:41.300 回答