Calling interrupt() only works if your thread is interruptable and if
your thread handles interruptions appropriately.

Your thread only is interrupted if the thread is doing I/O or is in a
wait-state (having called wait() on Object).

If you want to have background threads that do one-shot jobs and then
wait, use AsyncTask or the java.util.concurrent's ExecutorService .

And, you'd better read up on concurrent programming a little :-) It
can be tricky.

On Dec 16, 11:26 pm, Matt <[email protected]> wrote:
> Try storing the newly spawned thread as a field or collection in the
> appropriate class.  Then when you need to kill the thread, retrieve it
> and call Thread.interrupt().
>
> Matt
>
> On Dec 9, 6:15 pm, Richard Zhao <[email protected]> wrote:
>
>
>
> > My problem is:
> > Activity A called Activity B, and in Activity B, it start a background
> > thread to do some client-server work. But it maybe takes too much
> > time. So i add a cancel button to call the stop() method to stop the
> > thread, and call finish() to finish the Activity B and go back to
> > Activity A. Although it is back to Activity A, the thread isn't stop
> > immediately.
>
> > Can i just call the finish() to go back to Activity A, and leave the
> > thread to exit by itself?
> > If it is not the right way, which is?
>
> > Thanks for any help.- Hide quoted text -
>
> - Show quoted text -

-- 
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