Killing android application from task manager kills services started by app
Asked Answered
M

4

6

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

Marine answered 6/7, 2012 at 14:38 Comment(2)
"I want the services to keep running even after application exits" -- there is no "application exits" in Android.Weigle
Only the back button and all of its overridden glory. :-/Eward
H
9

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

Hamiltonian answered 6/7, 2012 at 14:41 Comment(8)
Thanks Tim. I need to find another way to start my serviceMarine
@bsengar No, actually you need to respect the fact that the user wanted to stop your application. Any attempt the circumvent the users will to stop your application is considered malicious. It is after all their device, not yours.Hamiltonian
@bsengar And as we said, regardless how HOW you start the service, it will die when the application is killed. I recommend just creating a really good save state algorithm and letting it be.Eward
"It is after all their device, not yours" - Well, its actually my company's device which is given to them so that the organisation can make sure the application is running all the time. They have contract with the company and are aware of this application running. The problem however is, they kill the application and then tell us that the application died by itself. Well...unfortunately Android doesn't support this kind of featuresMarine
@bsengar "unfortunately Android doesn't support this kind of features" -- The stock builds of the OS that are released on devices sold to the general public do not support it because it is malicious. However the beautiful thing about Android is you are free to checkout your own copy of the OS source and make the modifications necessary to allow for this behavior. Which is what you'll have to do if you want to make your implementation truly enforceable.Hamiltonian
How do you know the users are killing the application?Paradrop
@Tim I was actually referring to OP's comment that "they kill the application and then tell us the application died". I'm wondering if he can really be sure that is happening, or if he just assumes that is happening. I've no issue with your answer, I was just getting in on the discussion in comments.Paradrop
@DavidWasser ahh, I see. I cannot speak on his behalf, but one possibility is that they have ACRA or some other crash reporting that would tell them if they application had died, but not if it had been manually stopped. Pure speculation on my part though. I'd be interested to know his response too.Hamiltonian
E
2

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.

Eward answered 6/7, 2012 at 14:42 Comment(0)
F
0

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

Foursquare answered 6/7, 2012 at 15:13 Comment(0)
W
0

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://mcmap.net/q/245666/-android-service-restarting-when-application-is-killed-duplicate

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.

Wedurn answered 4/5, 2016 at 10:14 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.