Yes, there is that special case for orientation changes, thank you, but it's
temporary.

I suppose also if the UI thread is stuck on something and is heading for an
ANR, then it's not processing messages either.

Under normal conditions, the UI thread does process messages - here is a
simple test (I was curious about the messaging behavior here, so spent a few
minutes writing one):

>>>>> ---------------------------
new AsyncTask<Void, Void, String>() {
private Context context = getApplicationContext();

@Override
protected void onPostExecute(String result) {
Toast.makeText(context, "AsyncTask says: " + result,
Toast.LENGTH_SHORT).show();
}

@Override
protected String doInBackground(Void... params) {
try {
Thread.sleep(1000 * 5);
} catch (InterruptedException x) {
  Log.i(TAG, x.toString());
}
return "Hello world";
}
}.execute();
<<<<<--------------------------

You can put this in onStart of any activity (the main one will do), launch
it, and immediately press <Back> so that the activity is not only paused,
but also destroyed.

Five seconds later the toast will show up over the home screen, showing that
onPostExecute did get called.

-- Kostya

2011/1/23 Mark Murphy <[email protected]>

> On Sun, Jan 23, 2011 at 12:56 PM, Kostya Vasilyev <[email protected]>
> wrote:
> >  so your onPostExecute will get called as soon as
> > doInBackground completes.
>
> Not necessarily.
>
> When doInBackground() completes, the background thread from the thread
> pool sends a Message to a Handler, to cause onPostExecute() to be run
> on the main application thread.
>
> If the main application thread is not processing messages at this
> time, then the onPostMessage() Message will be stuck in the queue
> until such time as that state changes.
>
> For example, during a configuration change, messages are not processed
> on the old activity from onRetainNonConfigurationInstance() onward.
> And, messages will not start up again until the new activity completes
> onCreate(). This is how we can safely pass the AsyncTask from old to
> new, and associate that task with the right activity, without
> onPostExecute() being invoked during this transition.
>
> I *think* that messages for an activity are not processed when it is
> paused, but I'm not certain, as I haven't tried to test that specific
> scenario, and I don't remember a particular Googly note on the
> subject. Heck, the only reason I know what I wrote in the previous
> paragraph is courtesy of a post on this list from Ms. Hackborn.
>
> --
> Mark Murphy (a Commons Guy)
> http://commonsware.com | http://github.com/commonsguy
> http://commonsware.com/blog | http://twitter.com/commonsguy
>
> _Android Programming Tutorials_ Version 3.1 Available!
>
> --
> 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]<android-developers%[email protected]>
> 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 [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