3. Do something to tell your threads to shut down of their own accord in onPause().
Yea that is what I'm asking, what to do to tell the thread to shut down (I'd rather pause it). From your answer below I'm assuming you are completely killing the threads and restarting at the beginning on onresume, is that correct? Mark Murphy wrote: > Ben Williamson wrote: > >> Hey all, wondering if anyone knew the proper way to suspend your >> background threads when a user opens a new window. I see that suspend is >> deprecated and it warns it may cause deadlocks. >> > > If by "new window" you mean "new activity", then: > > 1. Have your thread-spawning activity implement onPause() and onResume(). > > 2. Start your threads in onResume() (not onCreate()). > > 3. Do something to tell your threads to shut down of their own accord in > onPause(). > > 4. Have the threads honor whatever you did in #3. > > For example, I tend to isolate long-running background work into a > Service, and use a LinkedBlockingQueue to control what work gets done. > When the threads need to stop due to onPause(), I just post an object on > the queue that indicates "yo! thread! stop!", and the thread drops out > of the pull-the-work-off-the-queue loop at that time. > > --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Android Beginners" group. To post to this group, send email to android-beginners@googlegroups.com To unsubscribe from this group, send email to android-beginners-unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-beginners?hl=en -~----------~----~----~----~------~----~------~--~---