My background service performs the core functionality of my app and is first started when the UI is opened.
So when the app is updated on the play store, the service is killed but the UI may not be opened again(So I guess the Service does not start again too).This is bad for me as the service performs the core functionality of the app. How do I overcome this?
Any help is deeply appreciated
Your service will be killed during upgrade. You need to catch upgrade event and start it again.
In Manifest.xml
<receiver android:name=".yourpackage.UpgradeReceiver" android:enabled="true" android:exported="true">
<intent-filter>
<action android:name="android.intent.action.MY_PACKAGE_REPLACED"/>
</intent-filter>
</receiver>
In UpgradeReceiver.java
public class UpgradeReceiver extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
try {
if (!Intent.ACTION_MY_PACKAGE_REPLACED.equals(intent.getAction()))
return;
// Start your service here.
} catch (Exception e) {
Utils.handleException(e);
}
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With