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.
>
>    
I think a better way to have phrased my question is....

"public final void suspend()
This method is deprecated. May cause deadlocks."

is in the javadoc for the Thread class.... is there an alternative to 
this method so I do not have to kill and completly start over each time 
I need to pause my activity.

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

Reply via email to