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. -- Mark Murphy (a Commons Guy) http://commonsware.com _The Busy Coder's Guide to Android Development_ Version 2.0 Published! --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Android Beginners" 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-beginners?hl=en -~----------~----~----~----~------~----~------~--~---

