I have the below code to set up an alarm from my app.
Intent intent = new Intent("MY_ALARM_NOTIFICATION");
intent.setClass(myActivity.this, OnAlarmReceive.class);
intent.putExtra("id", id);
PendingIntent pendingIntent = PendingIntent.getBroadcast(
myActivity.this, Integer.parseInt(id),
intent, PendingIntent.FLAG_UPDATE_CURRENT);
Calendar timeCal = Calendar.getInstance();
timeCal.set(Calendar.HOUR_OF_DAY, hour);
timeCal.set(Calendar.MINUTE, minutes);
timeCal.set(Calendar.DAY_OF_MONTH, day);
timeCal.set(Calendar.MONTH, month - 1);
timeCal.set(Calendar.YEAR, year);
Date date = timeCal.getTime();
AlarmManager alarmManager = (AlarmManager) getSystemService(ALARM_SERVICE);
alarmManager.set(AlarmManager.RTC_WAKEUP, timeCal.getTimeInMillis(), pendingIntent);
What happens when I remove my application from settings ? Do the alarms remain ?
The Alarm Manager holds a CPU wake lock as long as the alarm receiver's onReceive() method is executing. This guarantees that the phone will not sleep until you have finished handling the broadcast. Once onReceive() returns, the Alarm Manager releases this wake lock.
Alarm Bells Are Ringing The package exposes an AndroidAlarmManager object that has the following (relevant) methods: oneShot - trigger a one time alarm. oneShotAt - trigger a one time alarm at a specific date. periodic - trigger an alarm within a defined time interval.
Alarms let you send intents at set times or intervals. You can use alarms with broadcast receivers to start services and perform other operations. Alarms operate outside your app, so you can use them to trigger events or actions even when your app isn't running, and even if the device is asleep.
The events you schedule via AlarmManager
are removed when the app that scheduled them is uninstalled.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With