Faerbit / android-crond

Simple Android app which implements crond using AlarmManager
MIT License
26 stars 6 forks source link

Marshmallow Doze issue #13

Open a1291762 opened 6 years ago

a1291762 commented 6 years ago

On Marshmallow (23) and up, Doze mode can kick in and prevent timers from firing. I normally have my phone on a charger overnight, which apparently stops Doze mode from engaging. However, last night I did not, and as a result, crond did not start my job at the correct time.

There is a whitelist that end users can use that can help (Settings -> Battery -> Battery Optimization), but the best way to avoid the issue is to call a different API method:

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
        alarmManager.setExactAndAllowWhileIdle(AlarmManager.RTC_WAKEUP, next.getMillis(), alarmIntent);
    } else {
        alarmManager.setExact(AlarmManager.RTC_WAKEUP, next.getMillis(), alarmIntent);
    }