简体   繁体   中英

Android AlarmManager not firing after Google Play update

I've created an App reminding people to take madications on time. Every time, after I place a new APK on the Google Play, I get many complaints the alarm doesn't work anymore. It begins working again only after the user starts the App (or reboots). Help!

Check out the ACTION_MY_PACKAGE_REPLACED intent action (on honeycomb and up).

You should be able to register a broadcast receiver for it in the manifest that can then reschedule your alarms.

Scheduled alarms will NOT be cancelled on upgrades. I verified this for Android versions 2.2 and 4.3 and the latest Google Play at the time of writing.

What you have to make sure is that your new versions can handle all pending intents of any older version. That means:

  • same target definition in the manifest (broadcast receiver or service)
  • same intent "contract": actions, extras, etc.

My app runs a receiver for android.intent.action.MY_PACKAGE_REPLACED. When the receiver gets an ACTION_MY_PACKAGE_REPLACED Intent, it tears down all previous alarms and sets up new ones (because an update could change the alarm times). After testing, I've found that:

  • in development, deploying directly to a device using 'adb install -r app.apk', the updated app won't get alarms until I've manually launched the app.
  • after updating via Google Play Store, the updated app gets the alarms without the need for any interaction with the app at all after the update is done.

I wish Google would make this stuff clear - it was a very, very high risk test since if the updated app hadn't got the alarms it would have broken the app for all my users! But I'd tried everything else I could think of and I was 99.9% sure it had to work or how would any app every trust any of its alarms would ever get fired if updates disabled them.

I hope that helps someone stuck in the position I was in avoid wasting days in pointless testing.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM