I have a question on scheduling an event using AlarmManager with ELAPSED_REALTIME.
I want to schedule an intent after 30 minutes except sleeping time. Which of the following code I should use?
Code 1:
AlarmManager am = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE);
am.set(AlarmManager.ELAPSED_REALTIME,
30000, myIntent);
Code 2:
AlarmManager am = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE);
am.set(AlarmManager.ELAPSED_REALTIME,
SystemClock.elapsedRealtime() + 30000, myIntent);
Thanks.
Technically, neither. “after 30 minutes except sleeping time” isn’t supported.
elapsedRealtime()counts sleeping time.Ignoring that, you would want “Code 2”.