0

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.

1
  • 2
    Shouldn't it be 30 * 60 * 1000?
    – Yi H.
    Apr 21, 2012 at 11:46

1 Answer 1

2

Technically, neither. "after 30 minutes except sleeping time" isn't supported. elapsedRealtime() counts sleeping time.

Ignoring that, you would want "Code 2".

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.