Androidme
Androidme

Reputation: 3155

Killing android application from task manager kills services started by app

My application has one activity which starts two services but does not bind them. If I select return button to exit application (I cannot see it in task manager), both of the services started by application keep running. However, if I goto task manager and kill application, both of the services are stopped. I am not sure if it is intended behaviour but I want the services to keep running even after application exits. Any thoughts please.

Thanks

Upvotes: 6

Views: 7354

Answers (4)

Piotr Wittchen
Piotr Wittchen

Reputation: 3922

As it was already mentioned, it's expected behavior. Killing an app, which started the Service should kill running Service as well. If you want to keep your Service running when app is killed, you should start the Service in a separate process, what can be achieved by the following declaration in the Manifest:

<service
    android:name=".ServiceClassName"
    android:process=":yourappname_background" >
    ...

Reference: https://stackoverflow.com/a/15474347/1150795

Please note that usually app is not killed until a user explicitly kills it from the task/app manager or system kills it due to limited resources, low battery or similar reason. I'm not sure if it's typical use case to handle such things and if you really need to care about that.

Upvotes: 0

Mohsin Naeem
Mohsin Naeem

Reputation: 12642

I am not sure! But you should give a try to this

Upvotes: 0

ahodder
ahodder

Reputation: 11439

This is the behaviour expected. Services do not run in their own process. When you application is killed, your entire process dies with it.

In the documentation I attached, there is an orange block a page down (unfortunately, I don't think I can link to it :-( ) That will tell you pretty much what a service is in a nutshell.

Upvotes: 2

FoamyGuy
FoamyGuy

Reputation: 46856

That is the intended behavior of Task Managers (and force stop in ManageApplication). What good would stopping an application do if it left running the background work that the application was doing?

There is no way for you to prevent the user from killing your service on a stock version of Android OS

Upvotes: 9

Related Questions