Dianne,

With all due respect, HandlerThread or Thread do NOT convey the message that
they can be used with the UI in the same way that an AsyncTask does. In fact
even a small para saying something like

AsyncTask runs as a separate thread and does interact with the Activity's
lifecycle. It is associated with the instance that executed the AsyncTask,
however the onProgress and onResult are called in the main UI thread that
deals with the currently active instance which could be different than the
one that executed the AsyncTask. Thus the developer must ensure that any
reference to the Activity or UI components are not stale.

would help, IMHO.

I think we are beating a dead horse here and way off topic for the OP, so I
will stop...

On Sun, Oct 3, 2010 at 1:13 AM, Dianne Hackborn <hack...@android.com> wrote:

> On Sat, Oct 2, 2010 at 3:39 PM, Prakash Iyer <thei...@gmail.com> wrote:
>
>> Each his own. Try writing a AsyncTask that say lives for more than 10s and
>> in the final result say updates a text field. Now before the AsyncTask
>> completes, just change the orientation. I'd bet most developers would assume
>> the text field will get updated. Most developers would be wrong as the
>> AsyncTask's onResult will be calling the original object's (the one that did
>> the execute) text field and not the one that is currently displayed. Can you
>> make sure this works? Yes! Should this be documented? I would think it is
>> absolutely essential.
>
>
> This has *nothing* to do with AsyncTask, this is all about the
> peculiarities of Activity.  You will run into the same issue if you use
> HandlerThread, a raw Thread()...  heck, you'd even have the issue if you
> didn't use another thread at all but just Handler.postDelayedMessage().
>
> This behavior is documented in the material Activity; it doesn't make any
> sense to try to document this in every other generic facility for
> asynchronicity just because if you use that with an Activity you will need
> to understand how Activity instances can be fairly transient.
>
> And what you need to do with AsyncTask is *different* depending on where
> you are using it -- in an Activity, or a Service, or a View, or whatever.
>  They each have their own sometimes subtle details about lifecycle that you
> need to understand when introducing asynchronicity.  AsyncTask can't try to
> document exactly how to use it when combined with every other possible
> facility.
>
> --
> Dianne Hackborn
> Android framework engineer
> hack...@android.com
>
> Note: please don't send private questions to me, as I don't have time to
> provide private support, and so won't reply to such e-mails.  All such
> questions should be posted on public forums, where I and others can see and
> answer them.
>
>  --
> 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<android-developers%2bunsubscr...@googlegroups.com>
> For more options, visit this group at
> http://groups.google.com/group/android-developers?hl=en
>

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

Reply via email to