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 SharedPreferences with a FIRST_RUN 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 FIRST_RUN to false, else I do nothing.

  • What is the use of private Content Providers?
  • Android Wi-Fi Direct read rssi signal strength
  • Android: FragmentPagerAdapter: getItem method called twice on First time
  • TextInputLayout :How to give padding or margin to hint?
  • Extract code country from phone number
  • Aspectj with android library
  • But I noticed also that these preferences remain intact between app upgrade !

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

    How to handle such case ?

    Thanks in advance

    Related posts:

    Get current location address for android app
    Different named Markers on Google Android Map
    creating background drawable using layer-list, icon getting stretched
    Android. Scrolling 2 listviews together
    source value 1.5 is obsolete and will be removed in a future release
    Error :
  • ProGuard Cannot Find Referenced Libraries
  • API to automatically upload apk to Google Play?
  • Navigation drawer icon arrow instead of three lines
  • The Google Play services resources were not found. Check your project configuration to ensure that the resources are included
  • connect to device with Bluetooth address on String
  • Clear notification in status bar after application crashed
  • 4 Solutions collect form web for “How to know my Android application has been upgraded in order to reset an alarm?”

    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.

    Solution by Daniel Lew :

    Need a receiver with the following lines in manifest :

    <receiver android:name=".OnUpgradeReceiver">
        <action android:name="android.intent.action.PACKAGE_REPLACED" />
        <data android:scheme="package" android:path="" />

    android:path is used in order to prevent OnUpgradeReceiver to be triggered by any upgrade of any application.

    Simply, listen to the android.intent.action.MY_PACKAGE_REPLACED … This INTENT will notify you if a new version of your application has been installed over an existing one

    Note: This intent can is available starting from API 12

    For the Android OS v12 and above you need to register BroadcastReceiver with action ACTION_MY_PACKAGE_REPLACED

    <receiver android:name=".MyBroadcastReceiver">
        <action android:name="android.intent.action.MY_PACKAGE_REPLACED" />
    Android Babe is a Google Android Fan, All about Android Phones, Android Wear, Android Dev and Android Games Apps and so on.