tbruyelle tbruyelle - 10 months ago 44
Android Question

How to know my Android application has been upgraded in order to reset an alarm?

I noticed that an alarm is disabled when the application which sets this alarm has been upgraded. Is that true ?

Until now, I used the

with a
key in order to know if it's the first run of my application. If I don't find this key, I enable the alarm and set
to false, else I do nothing.

But I noticed also that these preferences remain intact between app upgrade !

So after an upgrade, the
key is already false, so I do nothing while my alarm need to be enabled.

How to handle such case ?

Thanks in advance


I've never tried this myself, but what about creating a BroadcastReceiver that listens to the ACTION_PACKAGE_REPLACED Intent?

I've thought about trying this before, but I'm not sure if there's a chicken-and-egg problem with it or not (e.g., does the Intent get sent before the new upgraded application can receive it?). Worth a try, though.