Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What happens to background service when the app is updated in android?

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)?

like image 270
kamalkishor1991 Avatar asked May 16 '15 19:05

kamalkishor1991


People also ask

What happens when app is updated in Android?

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.

What happens when app goes to background Android?

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.

How run service in background Android when app is killed?

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.

How Services is working in the background?

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.


2 Answers

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.

like image 59
Marcin Orlowski Avatar answered Nov 15 '22 02:11

Marcin Orlowski


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.

like image 21
Ashish Krishnan Avatar answered Nov 15 '22 00:11

Ashish Krishnan