android get activity returns null

前端 未结 2 1020
再見小時候
再見小時候 2020-11-28 11:20

I am using Action Bar on an Activity. For each Tab I am showing different layout. Since the layout is too heavy. So I am inflating each layout into a view. So on each Tab se

2条回答
  •  谎友^
    谎友^ (楼主)
    2020-11-28 12:09

    This can happen if you create an anonymous object inside a fragment that calls getActiviy(). If getActivity() is called in the anonymous object after the fragment is popped off the fragment stack, getActivity() will return null. At that point, the fragment is no longer associated with an activity.

提交回复
热议问题