源码版本:26.0.0-beta1

Fragment 的生命周期是依赖Activity的,假设在Activity的onCreate中有如下代码,

1
2
3
4
SearchFragment searchFragment = new SearchFragment();
getSupportFragmentManager().beginTransaction()
.replace(R.id.container, searchFragment)
.commitAllowingStateLoss();

探究一下Fragment的生命周期是如何依附的。

思维导图

Fragment启动生命周期