-
Notifications
You must be signed in to change notification settings - Fork 2.1k
3、onSupportVisible()等
YoKey edited this page Aug 8, 2017
·
3 revisions
onSupportVisible()
等生命周期调用顺序:onActivityCreated()
-> onResume()
-> onSupportVisible
-> onLazyInitView()
=> onSupportInvisible()
-> onPause()
public class MyFragment extends SupportFragment{
@Override
public void onSupportVisible() {
super.onSupportVisible();
// todo,当该Fragment对用户可见时
}
@Override
public void onSupportInvisible() {
super.onSupportInvisible();
// todo,当该Fragment对用户不可见时
}
}
这2个方法会在Fragment可见时回调,即:只要该Fragment对用户可见时,即会被调用,包括嵌套的子Fragment。
比如A内有个子FragmentB,B通过A startFragment(C) (此时A和C是同级Fragment),当你pop(C)时,A和B的onSupportVisible()都会被回调。
我相信这2个方法在单Activity多Fragment等嵌套较多的结构上,开发过程会方便很多!