NPE in Fragment.setUserVisibleHint() when using ViewPager

后端 未结 3 615
失恋的感觉
失恋的感觉 2021-01-11 17:32

I am at a loss for this. I am switching tabs manually in my ViewPager. I have this code inside my Activity:

@Override
public void onBackPressed()
{
    if (c         


        
3条回答
  •  既然无缘
    2021-01-11 18:03

    I had a bad time of a very similar case (same Exception in Fragment.setUserVisibleHint) even if I used FragmentStatePagerAdapter. There was random (thus difficult to reproduce) crash of my app when the underlying datas where changed.

    In my case, I finally was able to get rid of this crash by overriding the following method in the adapter :

    @Override
    public void restoreState(Parcelable state, ClassLoader loader) {
        // don't super !
    }
    

    I do think that there's a bug in this class, given the number of questions similar to this one in StackOverflow.

    I hope this could be useful to someone.

    Edit : I posted a similar answer to android.support.v4.app.Fragment.setUserVisibleHint null pointer on app resuming however, I'm not positively certain that these questions are duplicate. However, I think that this answer could help some people finding these for a similar symptom. How should I note this ?

提交回复
热议问题