9

I have an app running on Android that creates an alarm that is fired every 24 hours. This alarm is working as expected.

However, when I update my app through Google Play this alarm is lost because the end user does not open the app right after the app was updated.

My opinion is that Android is deleting the alarms my app created when the app was updated.

Does anyone already got this situation? Is there any way to persist the alarms when the app is updated?

Jonathan Leffler
  • 666,971
  • 126
  • 813
  • 1,185
user3012738
  • 131
  • 3
  • you are correct and this is the expected behavior. anytime you app gets updated any alarms get stopped and the only way to start them again is to open the app – tyczj Jun 06 '14 at 18:29

2 Answers2

17

Your solution is as simple as below:

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

  1. "android.intent.action.BOOT_COMPLETED" - called when you device restarts. Alarms are cancelled when device is shut down.
  2. "android.intent.action.MY_PACKAGE_REPLACED" - 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". In this receiver you can start your alarms again.

Ishaan
  • 3,009
  • 2
  • 19
  • 34
0

Yes you are correct. Once the app is updated the service, alarms and process of the app will be stopped. The updated apps will be in the stopped list of Andorid os.

Then only the alarm can be started once after the first manual launch of that application.

ImMathan
  • 1,919
  • 3
  • 23
  • 34