android - Activity Recognition PendingIntent 停止在半夜被调用

标签 android google-play-services android-pendingintent activity-recognition android-intentservice

我的应用程序会定期收集 Activity Recognition 检测到的 Activity 数据。 我实现了 exactly as described in the documentation , 但间隔一分钟。

只要用户登录 - 应用程序注册了 PendingIntent 以接收来自 google play 进程的更新..

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

问题:在某些设备中(在 Nexus 5 中最常发生),在半夜持续了 5-6 个小时 - IntentService 停止了叫。

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

对我的应用来说,了解每分钟的当前 Activity 大约是什么很重要,即使它保持不变或长时间闲置也是如此。

我的问题:

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

最佳答案

根据 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.

如你所料。没有理由不能使用 the many data storage techniques 保存最后一个值- 一个简单的 SharedPreference可能足以满足您的需求。

如果您直接根据正在调用的 IntentService 触发操作(这是一个坏主意,因为其他应用程序可能会导致它触发得非常快),而不是仅根据 Activity 的变化,那么您应该解耦这些操作,而不是 set an alarm或触发 periodic sync adapter对于您需要的任何特定时间间隔,从您收到的最后一个 Activity 中读取当前值。

关于android - Activity Recognition PendingIntent 停止在半夜被调用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24177858/

相关文章:

android - 改造给出 java.lang.VerifyError

android - 不使用eclipse项目导入google play服务

android - 单击状态通知打开特定文件夹

android - GcmTaskService 可以运行异步任务吗?

安卓应用内订阅 : Inventory call returns purchase as null even if purchase exists

android - 从推送通知打开安卓应用

android - 如何使用通知 addAction 调用方法或电话号码

android - ORMLite 查询外键

java - 缩放 ImageButton 以适应各种屏幕尺寸

Android 内存管理 : Screen density, 请求的图像大小和可用堆