Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Alarmmanager when app is updated [duplicate]

Tags:

java

android

Im working on an app that uses AlarmManager for some processes. I wanted to ask that if i update my app on the playstore. (update not new install) will registered alarms get canceled? Also will values of SharedPreference get reset?

like image 352
Shweta Dhingana Avatar asked Apr 07 '18 07:04

Shweta Dhingana


1 Answers

Alarms: Yes, they will get canceled but you can restart your alarms.

Here is the solution from this post https://stackoverflow.com/a/34464059/3474021

Have a broadcast receiver registered within your app with 2 intent filters namely:

  1. android.intent.action.BOOT_COMPLETED (docs) - called when your device restarts. Alarms are cancelled when device is shut down.
  2. android.intent.action.MY_PACKAGE_REPLACED (docs) - called once your app is reinstalled or updated from play store or from any source.

You will also need the permission android.permission.RECEIVE_BOOT_COMPLETED to receive android.intent.action.BOOT_COMPLETED. In this receiver you can start your alarms again.

SharedPreferences: No, they will remain when an app is updated.

like image 166
wprenison Avatar answered Nov 04 '22 20:11

wprenison