I’m instantiating and executing an AsyncTask from my UI thread (in the
onCreate() handler of my Activity). I guarantee that the Activity
doesn’t restart due to config changes (it ignores orientation change,
for example).
In my Activity.onCreate(): I use asynctask.execute(), then the UI
thread does some job, and then asynctask.get(…) is called to synchronize before Activity.onCreate() ends.
According to the log, my asynctask.onPostExecute() gets called ages
after asynctask.get() returns. More precisely, onPostExecute is called
after Activity.onResume (!) returns. (So it does get called, my method definition is OK,I use @Override, too.)
I read it somewhere that that since onPostExecute() posts in the
handler of the UI thread, the UI thread must be ready for it — why
isn’t it ready in this case? My application starts with orientation change, but it doesn’t cause any config change because of my settings in the manifest.
Is there any guarantee when will onPostExecute() be called relative
to asynctask.get() ?
get()only waits fordoInBackground()to complete, based on my reading of the source code.onPostExecute()will be called sometime afterget()returns, based on my reading of the source code. However, this is not a “guarantee”, insofar as this behavior is undocumented and therefore subject to change.