Fragment Life cycle from onPause to OnResume
In Activity life cycle we can go from OnPause to Onresume directly (this can occur if our activity leaves the foreground but is still visible, ie a dialog pop ups). Checking the fragment life cycle diagram: http://developer.android.com/guide/components/fragments.html
When the activity is paused then the fragments respective onPause is called. But at this point when the activity call onResume what state is the fragment in ? What life cycle callback gets called ?
onResume,请查看官方文档:http://developer.android.com/reference/android/app/Fragment.html#onResume()
The Fragment lifecycle is tied to the Activity lifecycle. If the Activity is changing the state the Fragment will aswell. Because of that a Fragment has the same major lifecycle components as an Activity like onCreate(), onResume and so on. In addition to these, there are some specific ones like onAttached(), onDetached(), onActivityCreated() etc.
A Fragment is able to draw an UI and is controlled by the Activity. If that wouldn't be the case some strange things could happen. Like the Activity goes into the background but the Fragment is still visible. That's why these two components have to sync their state.
链接地址: http://www.djcxy.com/p/65702.html上一篇: 片段显示和活动生命周期