I found this article to be very insightful because I too am just
learning about managing multiple threads.
http://articles.techrepublic.com.com/5100-10878_11-5144546.html

I ended up using a shared volatile variable that is check when I'm
doing this that take alot of time in the background thread, if it's
false the thread will exit accordingly.  Also in my app's onStop()
method I make sure to check to see if the thread is running and stop
it if it is.

-theSmith

On Dec 18, 5:44 pm, Streets Of Boston <[email protected]> wrote:
> 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