开发者

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?

  1. Refactoring the service to only handle commands as they come in, and not spawning a thread
  2. 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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜