Reputation:
Suppose I implement a service that starts threads performing long-running operations. If the service gets killed, will that automatically kill off those running threads as well?
Thanks.
Upvotes: 1
Views: 682
Reputation: 29
I have found this to also be true. I wanted a thread in a background service (Main UI process). I wanted the service to be killed when the main activity was killed, however I found that my threads would keep on running even when the activity and service (stopSelf) had stopped/been stopped.
I had to explicitly kill the thread. I did this by calling yourThread.interrupt().
Upvotes: 0
Reputation: 628
A service runs in the same process as your app unless you specify otherwise in the manifest. If it's killed (i.e., crashes) then all threads belonging to the process will disappear, but I don't think that's what you're asking. Threads started by the service will not be terminated automatically if the service is stopped in the normal way, unless the service is running in another process and the process is also terminated. It may not be. Android tends to keep processes around even after the Activity or Service that was running in them has been stopped and destroyed.
Upvotes: 0