Let's say I started a repeating background service that was stated on first app launch and on boot. What happens when I provide an update of the app. Will that background service be killed? Will user have to open the app again to register the background service again or app will get some callback on update?
Edit-1: As one of the answer suggest if app has to be relaunched again to start the service then how does alarm application works fine after the update without relaunching(I believe it usages background service to start the alarm)?
You can update your Android apps and the Play Store app one at a time, all together, or automatically. Updating your apps to the latest version gives you access to the latest features and improves app security and stability.
An app is running in the background when both the following conditions are satisfied: None of the app's activities are currently visible to the user. The app isn't running any foreground services that started while an activity from the app was visible to the user.
First, the easiest way to do what you're trying to do is to launch an Android Broadcast when the app is killed manually, and define a custom BroadcastReceiver to trigger a service restart after that. Dear Dr Sabri Allani, If your Service is started by your app then actually your service is running on main process.
For Android Developers, a Service is a component that runs on the background to perform long-running tasks. A Background Service is a service that runs only when the app is running so it'll get terminated when the app is terminated. A Foreground Service is a service that stays alive even when the app is terminated.
Will that background service be killed?
It will be killed.
Will user have to open the app again to register the background service again or app will get some callback on update?
It depends. Basically it'd require user activity as app is not relaunched automatically after update. But if you target API 12 or higher (which you should nowadays) you can try to use ACTION_MY_PACKAGE_REPLACED broadcast. As per doc:
Broadcast Action: A new version of your application has been installed over an existing one. This is only sent to the application that was replaced. It does not contain any additional data; to receive it, just use an intent filter for this action.
so you can do you stuff either in BroadcastReceiver
trigger something once you receive this broadcast.
The service will be killed and needs to started again.
A Service doesnt run on a separate process. The Service object itself does not imply it is running in its own process; unless otherwise specified, it runs in the same process as the application it is part of.
So when the application is updated, the application is sent to the stopped state.
You can test this. From google play store initiate a update for the app (which has a service E.g Whatsapp). Open the app and wait for it to complete. It stops. you can check the internal running processes. Connect the phone to DDMS. Check the processes.
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