您的位置:首页 > 移动开发 > Android开发

onDetach ,onAttach,onPostExecute,RetianFragment方法周期,解释的不错

2016-02-03 11:22 567 查看
It is not possible for 
onPostExecute()
 to
be called in between 
Fragment#onDetach()
 and 
Fragment#onAttach()
 during
a configuration change. The reasoning behind this claim is threefold:

Configuration changes are handled inside a single message in the main thread's message queue.

As soon as the 
doInBackground()
 method
returns, the 
AsyncTask
 schedules
the 
onPostExecute()
 method
to be invoked on the main thread by posting a message to the main thread's message queue.

The configuration change's message will contain the code that will invoke the 
Activity
 and 
Fragment
 lifecycle
methods (such as 
onDetach()
 and 
onAttach()
).
The 
AsyncTask
's
message will contain the code that will invoke the 
onPostExecute()
 method.
Since the main thread processes messages in its message queue sequentially, it is impossible for the two messages to be executed at the same time, and therefore 
onPostExecute()
 can
never be invoked in between the calls to 
onDetach()
 and 
onAttach()
.
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  RetianFragment Android