Answer the question
In order to leave comments, you need to log in
How to make a sleeping Android device periodically wake up and do useful work?
The idea is that the application should periodically (every 2-10 minutes) wake up the sleeping device, do some work, and then let the device sleep further.
According to the official documentation, the AlarmManager and its setExactAndAllowWhileIdle(…) method are best suited for this purpose. With a normal battery charge, it works with an accuracy of about 1 minute. In Doze mode, these alarms cannot go off more than once every 9 minutes (other sources say 15 minutes). However, an application can be added to a "Whitelist" that will allow it to ignore Doze mode.
The point is, it's all theory. In practice, it turns out that Android, in any case, acts at its own discretion, regardless of the "Accurate alarm clock", or the "White List", or the frequency of alarm calls. With one launch of the application, it executes all alarms for an hour and a half in a row; on the other hand, it performs only one or two of them, and the next one postpones until the device is manually unlocked, even if it happens only an hour later.
This is how my alarm clock looks like:
AlarmManager alarmManager = (AlarmManager) appContext.getSystemService(Context.ALARM_SERVICE);
Intent alarmIntent = new Intent(appContext, WakeUpReceiver.class);
PendingIntent alarmPIntent = PendingIntent.getBroadcast(appContext, 0, alarmIntent, 0);
long trigger = System.currentTimeMillis() + 120_000;
alarmManager.setExactAndAllowWhileIdle(AlarmManager.RTC_WAKEUP, trigger, alarmPIntent);
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question