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

2

6

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

Dioscuri answered 16/5, 2015 at 19:50 Comment(0)
S
7

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.

Schedule answered 16/5, 2015 at 20:3 Comment(1)
Sorry about simple question, but how does alarm application starts alarm after an update without any user activity?Dioscuri
W
1

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.

Willing answered 16/5, 2015 at 20:26 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.