Service lifetime problem
I currently have a thread that spawns and either pulls the next command off a queue and executes it or sleep for a bit and try again. However I do not want it to ru开发者_开发百科n if there are no more commands in the queue and there are no more activities alive in the application.
My question is what route should I investigate, and which routes might have other people taken?
- Refactoring the service to only handle commands as they come in, and not spawning a thread
- having a third condition in my thread (if !activityCount = 0 stop thread)
Or, do I have it wrong and android can terminate my thread automagically if there are no more activities bound to it?
There is a way to create a service that is stopped "automagically": see the Bound Services page in the Dev Guide:
A bound service typically lives only while it serves another application component and does not run in the background indefinitely.
精彩评论