That's right. The Java threads API has a way to do this with the function call. There isn't any difference in GC.
On Dec 29, 1:56 pm, theSmith <chris.smith...@gmail.com> wrote: > That would work also, you just have to remember that function calls > are never free and the GC on android is annoying enough as it is, no > need to give it more stuff to do. > > -theSmith > > On Dec 29, 1:43 pm, jotobjects <jotobje...@gmail.com> wrote: > > > Why not just call Thread.isInterrupted() instead of using the > > volatile? > > > On Dec 29, 9:24 am, theSmith <chris.smith...@gmail.com> wrote: > > > > 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 <flyingdutc...@gmail.com> 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 <hansen.matt...@gmail.com> 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 <zwher...@gmail.com> 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 android-developers@googlegroups.com To unsubscribe from this group, send email to android-developers+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-developers?hl=en