What happens to the alarms set via alarm manager by an app, if the app is uninstalled
Asked Answered
E

2

7

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 ?

Exaggeration answered 19/10, 2013 at 11:0 Comment(0)
Z
13

The events you schedule via AlarmManager are removed when the app that scheduled them is uninstalled.

Zayin answered 19/10, 2013 at 11:1 Comment(6)
do you know if it is the same iOS ?Exaggeration
@tony9099: I am not aware that iOS has AlarmManager, PendingIntent, etc. You would be better served asking a separate StackOverflow question, tagged with ios instead of android, to address your concern in iOS-specific terms.Zayin
@Zayin Is it similar in the case of "app update"? Is the pending intent given to alarm manager removed?Latterday
@Tejas: AFAIK, no.Zayin
I can verify CommonsWare's answer. Application updates DO NOT remove previous pending indents given to AlarmManager. Previously scheduled repeating alarms are fired normally, after an app update.Billman
Thank you for your answer and comments guys! This should be in google's official docs of AlarmManagerBrindabrindell
U
0

If you would like the reminders to persist after uninstall, you will need to add them to the Google Calendar of the user (or create a calendar) with an intent

  Intent intent = new Intent(Intent.ACTION_INSERT)
            .setData(CalendarContract.Events.CONTENT_URI)
            .putExtra(CalendarContract.EXTRA_EVENT_BEGIN_TIME, reminderDateTime.getMillis())
            .putExtra(CalendarContract.EXTRA_EVENT_END_TIME, reminderDateTime.getMillis())
            .putExtra(CalendarContract.Events.TITLE, "TITLE"
            .putExtra(CalendarContract.Events.DESCRIPTION, eventDescription)
            .putExtra(CalendarContract.Events.HAS_ALARM, true)
            .putExtra(CalendarContract.Events.ALLOWED_REMINDERS, new int[]{CalendarContract.Reminders.METHOD_ALARM, CalendarContract.Reminders.METHOD_ALERT})
            .putExtra(CalendarContract.Events.AVAILABILITY, CalendarContract.Events.AVAILABILITY_BUSY);
Underskirt answered 19/1, 2019 at 19:31 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.