0

Code:

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);

The service logs its activity. To do the test, I push the power to put the Android device to sleep. I wake up the device a few hours later to check the log and find the service is run according to the interval during the sleep. My understanding is that ELAPSED_REALTIME does not wake up the device to run. In other words, ELAPSED_REALTIME in this case behaves like ELAPSED_REALTIME_WAKEUP that wakes up the device to run a task.

Could anyone shed some light on this? Is there something wrong with the code or my test?

David Wasser
  • 93,459
  • 16
  • 209
  • 274
Hong
  • 17,643
  • 21
  • 81
  • 142

1 Answers1

0

You've got some other app running on your phone that is waking it up at intervals. Android will let your alarm trigger if the phone is already awake due to something else.

David Wasser
  • 93,459
  • 16
  • 209
  • 274
  • Thank you for trying to help. How can I ascertain this? I have tested this on a Tablet and a generic TV box. They behave the same. These two devices are used almost exclusively for testing apps. They do not have much else running on them. – Hong Mar 02 '18 at 21:53