Reputation: 181
I have AlarmManager set up to fire every minute. However, I only need it when phone is active. I want to turn off all updates when phone goes to sleep. I am not sure what the default behavior of AlarmManager and widgets in general is when phone goes to sleep. But I noticed that my battery goes down when in sleep mode. Hence, i believe its the widget thats bringing it down.
So, if AlarmManager and other broadcasts keep firing by default, how can I turn these updates off in sleep mode and then turn them back on when phone resumes active mode?
Upvotes: 1
Views: 117
Reputation: 106
Use public void setInexactRepeating (int type, long triggerAtMillis, long intervalMillis, PendingIntent operation)
with RTC as type. Only RTC_WAKEUP and ELAPSED_REALTIME_WAKEUP will wake up devices.
E.g. in my code I use
am.setInexactRepeating(AlarmManager.RTC, System.currentTimeMillis() + syncInterval, syncInterval, pendingIntent);
Upvotes: 1