开发者

Respond to kill requests by task managers

My situation:

I have created an Android service, which is started when the app is started. The service consists of a simple Thread that waits for 5 seconds, writes a log message and waits again.

After closing the application (using the back button), Android chooses to restart my service , because I am returning START_STICKY in OnStartCommand. When debugging the application, I can actually use DDMS to kill the process. Android again chooses to restart the service. This is expected as per the manual.

I also installed a task manager, and used that to "kill" the instance. Funky thing, is that now my service is no longer restarted.

The funky thing is this: in either case, no destroy code of my classes is called. No InterruptedException is raised on my waiting threads. There seems to be no way for my application to know it's being destroyed.

My question:

How can I get around this, and respond to kill requests? I already noticed that the DVM lacks sun.misc.Signal and sun.misc.SignalHandler for proper signal handling (if that's even being used by task killers).

I kind of need to know wether my app is being destroyed, so I can properly close file handles, database connections and the likes.

Many thanks 开发者_StackOverflowfor any assistance.


How can I get around this, and respond to kill requests?

You don't. OTOH, this task killer behavior should have been eliminated in Android 2.2, so it eventually will not be a problem.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜