[android-developers] Re: implementation of onDestroy for a service containing a worker or backround thread

2009-05-30 Thread Mike Hearn
Why does your service need to run all the time? That's pretty rare, and is going to impact battery life. --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Android Developers" group. To post to this group, send email to

[android-developers] Re: implementation of onDestroy for a service containing a worker or backround thread

2009-05-29 Thread Streets Of Boston
onDestroy() can still be called. If an activity calls stopService(...), the service's onDestroy may be called. On May 28, 12:24 pm, Gautam wrote: > Thanks... > The plan is to start the service once (startService()) and never call > stopService. I want my service to be running always (will set >

[android-developers] Re: implementation of onDestroy for a service containing a worker or backround thread

2009-05-29 Thread Gautam
Can some one please respond? Appreciate it. --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Android Developers" group. To post to this group, send email to android-developers@googlegroups.com To unsubscribe from thi

[android-developers] Re: implementation of onDestroy for a service containing a worker or backround thread

2009-05-28 Thread Gautam
Thanks... The plan is to start the service once (startService()) and never call stopService. I want my service to be running always (will set service.forground() = true). When any activity wants to use the service it would get the service via bind and invoke methods on the service. Also, by looki

[android-developers] Re: implementation of onDestroy for a service containing a worker or backround thread

2009-05-28 Thread Marco Nelissen
On Thu, May 28, 2009 at 7:12 AM, Mike Hearn wrote: > > Your understanding is wrong - your service can be killed at any time > without onDestroy being run. I'm not actually sure why onDestroy even > exists in this case, I found it was much more common for the kernel to > OOM kill my process than i

[android-developers] Re: implementation of onDestroy for a service containing a worker or backround thread

2009-05-28 Thread Mike Hearn
Your understanding is wrong - your service can be killed at any time without onDestroy being run. I'm not actually sure why onDestroy even exists in this case, I found it was much more common for the kernel to OOM kill my process than it was for the AM to nicely request my service to quit. Don't s

[android-developers] Re: implementation of onDestroy for a service containing a worker or backround thread

2009-05-28 Thread Streets Of Boston
Then you should call join() in onDestroy after calling myBackgroundThread.stopThread() causing onDestroy to wait until your background thread to end. Make sure that your background thread never blocks or takes too long to shut-down. If onDestroy is waiting too long, your user's ain't gonna be hap

[android-developers] Re: implementation of onDestroy for a service containing a worker or backround thread

2009-05-28 Thread Gautam
I need to make sure, that onDestroy returns only after proper clean up by the background thread. Else (according to my understanding) OS may kill the process hosting the service before proper cleanup. --~--~-~--~~~---~--~~ You received this message because you are

[android-developers] Re: implementation of onDestroy for a service containing a worker or backround thread

2009-05-27 Thread Streets Of Boston
Send a message to your background thread telling it to end. Your background thread: class MyBackgroundThread extends Thread { ... ... private boolean _isRunning = true; public void run() { ... ... while (running()) { ... // fetch and handle messages. ... } } .. pr

[android-developers] Re: implementation of onDestroy for a service containing a worker or backround thread

2009-05-27 Thread gautam_raychaudhury
Can I use the thread.join() mechanism? Basically, in the onDestroy() method of the service, I would send a message to the background thread and call join on the thread. The background thread would destroy it self after proper cleanup. But, what method should I use to exit the thread. Please note t

[android-developers] Re: implementation of onDestroy for a service containing a worker or backround thread

2009-05-26 Thread gautam_raychaudhury
Android may kill the process and thus the service running in the process, once onDestroy() returns (after sending a message to the worker thread). But how will I make sure that the service has completed it's clean up operations (ex. saving some data on to some storage, etc...), if any? The main t

[android-developers] Re: implementation of onDestroy for a service containing a worker or backround thread

2009-05-26 Thread Dianne Hackborn
Blocking in onDestroy() waiting for the background thread to complete basically defeats the purpose of doing work in a background thread. On Tue, May 26, 2009 at 7:09 AM, Gautam wrote: > > Hi, > > I'm implementing a service that contains a thread to handle all > time consuming operation. My c