android里为啥很多示例创建UI界面在onCreateView里

android里为啥很多示例创建UI界面在onCreateView里,我尝试放在onResume()里也是可以的,两个有啥区别?我之所以放在onResume()里,也是因为以下原因导致的
如下代码,year通过setFragmentResultListener监听正确拿到了。
但是我在onCreateView里使用还是个空字符串,
在onResume()里的值也是正确的,最后我把UI创建写在onResume()里,达到了我想要的效果

   private static String year="";
 @Override
    public void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);


        getParentFragmentManager().setFragmentResultListener("requestKey", this, new FragmentResultListener() {

            @Override
            public void onFragmentResult(@NonNull String requestKey, @NonNull Bundle bundle) {
                // We use a String here, but any type that can be put in a Bundle is supported
                year = bundle.getString("year_select");

                // Do something with the result

                Log.d("内部监听 income year 获取:",year);


            }
        });
    }

可以看下activity 和 fragment的生命周期。这两个方法在生命周期特定时期会被回调通知。

onresume() 会每次进入该activity,或者未销毁该ativity,被另一个ativity覆盖之后,回退到当前activty执行onresume。这里不应该放一些常规的
view初始化操作。

oncreatView(),返回的是View,系统会通过这个返回的View,进行界面渲染。并非必须在OnCreate()中创建View,在Oncreat()回调前任何时刻均可以。