【发布时间】: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