本文介绍了getActivity()在Fragment的onCreateView()方法中返回null的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

为什么getActivity()onCreateView()片段方法中返回null?

Why does getActivity() return null in onCreateView() method of fragment?

推荐答案

在这种情况下,getActivity()返回 null ,因为一旦onActivityCreated()活动方法被获取,则getActivity()将获得活动引用.会被调用,然后在片段的onCreateView()之后调用此方法.

In this case getActivity() is returning null because getActivity() gets the activity reference once the onActivityCreated() method of activity is called and this method is called after onCreateView() of fragment.

这篇关于getActivity()在Fragment的onCreateView()方法中返回null的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-24 13:36