On Apr 20, 3:24 pm, Mark Murphy <[email protected]> wrote:
> That does not imply, however, that the thread is interruptible. That's a
> Java thing, not an AsyncTask thing.
>

OK, that's what I needed to check on. The task is doing IO so it
should get interrupted eventually, but I could be catching it as an
IOException and continuing.

At any rate, the graceful cancellation works.


> I'm with Ms. Hackborn on this one -- I avoid designs that require Java
> threads to be stopped.
>
> > When Android kills the service, which it can do at any time without
> > warning, does it kill the Async threads?
>

> If by "kills the service" you mean "destroys the service", then no, I'm
> reasonably certain the threads are not killed. The AsyncTask will run to
> completion regardless of the status of the component that started is.
> Leastways, I'm rather sure this is what happens with activities, and I'm
> not aware of any differences with respect to services in this regard.
> AsyncTask maintains a thread pool, so even when the task is complete,
> the thread does not necessarily terminate.
>
OK, now I'm worried. I see a possible runaway task here with no way to
cancel.

I should of course call AsyncTask.cancel() in onDestroy()

But Ms. Hackborn has stated in previous threads that onDestroy() won't
necessarily be called when a service is destroyed.

> If by "kills the service" you mean "terminates the process", then yes,
> the thread will go away when the process goes away.
>
If the process is alway terminated when a service is destroyed without
warning, then I won't worry about the runaway task.

Nathan

-- 
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

Reply via email to