我正在从我的 UI 线程(在 我的 Activity 的 onCreate() 处理程序)。我保证 Activity 由于配置更改不会重新启动(它忽略方向更改, 例如)。
在我的 Activity.onCreate() 中:我使用 asynctask.execute(),然后是 UI 线程做一些工作,然后在 Activity.onCreate() 结束之前调用 asynctask.get(...) 进行同步。
根据日志,我的 asynctask.onPostExecute() 被调用了 ages 在 asynctask.get() 返回后。更准确地说,调用 onPostExecute 在 Activity.onResume (!) 返回后。 (所以它确实被调用了,我的方法定义没问题,我也使用@Override。)
我在某处读到,自从 onPostExecute() 发布在 UI 线程的处理程序,UI 线程必须为此做好准备——为什么 这种情况下还没有准备好吗?我的应用程序以方向更改开始,但由于我在 list 中的设置,它不会导致任何配置更改。
是否可以保证 onPostExecute() 何时被调用相对 到 asynctask.get() ?
最佳答案
根据我对源代码的阅读,According to the log, my asynctask.onPostExecute() gets called ages after asynctask.get() returns. More precisely, onPostExecute is called after Activity.onResume (!) returns.
get()
仅等待 doInBackground()
完成。
根据我对源代码的阅读,Is there any guarantee when will onPostExecute() be called relative to asynctask.get() ?
onPostExecute()
将在 get()
返回后的某个时间调用。但是,这不是“保证”,因为此行为未记录在案,因此可能会发生变化。
关于android - 部分订单 : AsyncTask. get() 和 onPostExecute()?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10461533/