【问题标题】:Why does ELAPSED_REALTIME behave like ELAPSED_REALTIME_WAKEUP为什么 ELAPSED_REALTIME 的行为类似于 ELAPSED_REALTIME_WAKEUP
【发布时间】:2018-08-11 01:58:21
【问题描述】:

代码:

Intent intent = new Intent(context.getApplicationContext(), UpdateWidgetService.class);
PendingIntent service = PendingIntent.getService(context,
                    MyCode,
                    intent,
                    PendingIntent.FLAG_CANCEL_CURRENT);
AlarmManager am = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE);
am.setInexactRepeating(AlarmManager.ELAPSED_REALTIME, SystemClock.elapsedRealtime(), iInterval, service);

服务记录其活动。为了进行测试,我按下电源让 Android 设备进入睡眠状态。几个小时后我唤醒设备查看日志,发现服务在睡眠期间按照间隔运行。我的理解是 ELAPSED_REALTIME 不会唤醒设备运行。换句话说,在这种情况下,ELAPSED_REALTIME 的行为类似于唤醒设备以运行任务的 ELAPSED_REALTIME_WAKEUP。

有人能解释一下吗?代码或我的测试有问题吗?

【问题讨论】:

    标签: android android-service android-widget android-alarms android-background


    【解决方案1】:

    您的手机上运行的其他应用程序会不时唤醒它。如果手机由于其他原因已经唤醒,Android 会让你的闹钟触发。

    【讨论】:

    • 感谢您的帮助。我怎样才能确定这一点?我已经在平板电脑和普通电视盒上对此进行了测试。它们的行为相同。这两种设备几乎专门用于测试应用程序。他们没有太多其他的东西在运行。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-06-20
    • 1970-01-01
    • 2017-05-28
    • 2013-09-18
    • 1970-01-01
    相关资源
    最近更新 更多