Search code examples
androidbackground-process

Android: what happens to background process when a new version is installed from the Market Place?


I have developed an Android health app which launches a process running in the background and monitoring user activities such as steps. If the app is closed by the user, the core sensors monitor keeps running in the background. I am about to upload a new version of the app to the marketplace. What will happen to the background service when the app is updated? Will it be killed? Tests on the beta channel seem to indicate that the background process is somehow left in a semi-dead status (i.e. the process is there but is not working). Shall I make sure that the background process stops when a new version is installed? If so, how? Thanks


Solution

  • All the processes are killed. If you want them to be restarted you have to set an intent filter with android.intent.action.MY_PACKAGE_REPLACED on the background processes. For example in my Manifest file I have created a receiver that has the following:

    <intent-filter>
    <action android:name="android.intent.action.BOOT_COMPLETED" />
    </intent-filter>
    <intent-filter>
    <action android:name="android.intent.action.QUICKBOOT_POWERON" />
    </intent-filter>
    <intent-filter>
    <action android:name="android.intent.action.MY_PACKAGE_REPLACED" />
    </intent-filter>
    

    This will guarantee that this receiver (which will restart the services) will restart after reboot and after package reinstall