0

My android app makes use of a service which is currently triggered if the app is opened (and service is currently not running), or if device is rebooted.

When I released the first update on Google Play I noticed that on updating the app from Google play on a device, the functionalities of the app as set through my service stopped working until I open the app once or reboot my device.

I hence put a message on Google Play asking all my current users using those functionalities to reopen the app for the functionalities to start working again.

Now I am planning to release another update for my app, but this time, I would somehow like to either make the service persist upon app update or restart the service on app update without forcing any user action, so that existing users will not experience any problems in using my app.

Any solutions with/ without code would be appreciated.

SoulRayder
  • 5,072
  • 6
  • 47
  • 93
  • The PackageManager sends broadcasts for app updates. Particularly, `android.intent.action.MY_PACKAGE_REPLACED` intent broadcast can be used to get a notification when your app gets updated. You can receive this broadcast from your service / app and restart your service based on that. https://developer.android.com/reference/android/content/Intent.html#ACTION_MY_PACKAGE_REPLACED – iVoid Apr 14 '17 at 11:13
  • http://stackoverflow.com/questions/30727953/android-app-update-broadcast. – Sai's Stack Apr 14 '17 at 11:15

1 Answers1

0

As user iVoid comments you can listen for the android.intent.action.MY_PACKAGE_REPLACED intent. Create a BroadcastReceiver and make sure you listen for it.

In your AndroidManifest.xml you declare a BroadcastReceiver

<receiver android:name=".MyReceiver">
    <intent-filter>
        <action android:name="android.intent.action.MY_PACKAGE_REPLACED"/>
    </intent-filter>
</receiver>

And in your MyReceiver class you can do whatever you want to do, like for instance restarting your service.

public class MyReceiver extends BroadcastReceiver {

    @Override
    public void onReceive(Context context, Intent intent) {
        ...
    }
}
halvdan
  • 51
  • 3