Reputation: 267
I want to program an app that has two independent, repetitive alarms. There are two classes seem to be able do this: AlarmManager
and AlarmClock
. I've tested AlarmManager
, but when Android restarts all alarms are cleared.
Which should I use?
Upvotes: 1
Views: 1667
Reputation: 31252
AlarmManager services allow you to schedule your application to be run at some point in the future. When an alarm goes off, the Intent that had been registered for it is broadcast by the system, automatically starting the target application if it is not already running.
You may find the SO post helpful Android AlarmManager
AlarmManager mgr=(AlarmManager)context.getSystemService(Context.ALARM_SERVICE);
Intent i=new Intent(context, OnAlarmReceiver.class);
PendingIntent pi=PendingIntent.getBroadcast(context, 0, i, 0);
mgr.setRepeating(AlarmManager.ELAPSED_REALTIME_WAKEUP, SystemClock.elapsedRealtime(), PERIOD, pi);
Whereas AlarmClock provider contains an Intent action and extras that can be used to start an Activity to set a new alarm in an alarm clock application.
Upvotes: 1
Reputation:
Use BroadcastReceiver to handle Android OS boot broadcast and reschedule your alarms.
Upvotes: 2