I'm setting multiple alarms so they can be repeated on specific days. Now I have heard that Android doesn't save the alarms on reboot. I have also read that BroadcastReceiver
should be used when BOOT_COMPLETED
to reschedule all the alarms.
But how do I tell the BroadcastReceiver to reschedule alarms after reboot if I have 5 alarms per day = around 35 alarms scheduled on different days. Do I need to store them in the database or? How do I store them? Or is the BOOT_COMPLETED all I need? Is there any example for this kind of thing? I couldn't find it.
This is what I currently have for setting the alarms and my simple receiver class. I'm using Service instead of BroadcastReceiver here because I have heard that BR should be used to only process short things and in the future I'll have to use some long sound clips.
private void setAlarm(){
Intent intent = new Intent(getBaseContext(), AlarmReceiver.class);
PendingIntent pendingintent = PendingIntent.getService(getBaseContext(), 2, intent, PendingIntent.FLAG_CANCEL_CURRENT);
AlarmManager am = (AlarmManager) getSystemService(ALARM_SERVICE);
am.set(AlarmManager.RTC_WAKEUP, System.currentTimeMillis() + sveskupa, pendingintent);
Toast.makeText(getBaseContext(), "Alarm is set", Toast.LENGTH_LONG).show();
}
AlarmReceiver class:
public class AlarmReceiver extends Service{
@Override
public IBinder onBind(Intent intent) {
// TODO Auto-generated method stub
return null;
}
@Override
public void onCreate() {
// TODO Auto-generated method stub
super.onCreate();
final MediaPlayer MPRadio1 = MediaPlayer.create(this, R.raw.radio3);
MPRadio1.start();
Toast.makeText(getBaseContext(), "OnCreate", Toast.LENGTH_LONG).show();
}