Conciser holding a WeakReference to the Activity from the AsyncTask.

On Tuesday, January 15, 2013 5:44:04 PM UTC, G. Blake Meike wrote:
>
>
>
> On Monday, January 14, 2013 6:13:34 PM UTC-8, Greenhand wrote:
>>
>> I considered IntentService before; however, I did not found a way to 
>> abort IntentService like the AsyncTask#cancel() mechanism.
>>
>
> That's an interesting point.
>
> Note, first of all, that wrapping a job in an AsyncTask doesn't actually 
> make it cancelable.  Unless the job will actually stop when interrupted or 
> something, you can call cancel on the AsyncTask all day long, to no effect.
>
> What AsyncTask *does* provide, is a pointer to the task you want to 
> cancel.  I should think that would be pretty easy to do with an 
> IntentService:  There is only one job running at any time.  Just interrupt 
> the thread or flag the job.
>
> If I try to null out the member variables and the activity reference in 
>> AsyncTask in onPause(), is it safe?.  I do not have to null out them unless 
>> they are static.
>
>
> If the AsyncTask holds a reference to an Activity, you'll leak the 
> activity.  That's true even if the reference is implicit (that is, if the 
> AsyncTask is an inner class and *not* static).  Making sure that the task 
> has no pointers to the Activity, after onPause, is safe.  On the other 
> hand, it brings up the question of why the Task is still running, if there 
> is nobody to whom to report a result...
>
> G. Blake Meike
> Marakana
>
> Programming Android 2ed is now in stores:
> http://bit.ly/programmingandroid
>
>

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