OnResume() not called in Fragment using tabLayout and ViewPager

I've solved the problem. I use setUserVisibleHint(boolean isVisibileToUser) instead onResume(). Like this:

 @Override
public void setUserVisibleHint(boolean isVisibleToUser) {
    super.setUserVisibleHint(isVisibleToUser);
    if(isVisibleToUser) {
        init();
    } else {

    }
}

Thank you all!


The accepted answer did not work for me. However, I found a solution to the problem.

Just initialise your FragmentStatePagerAdapter with the following constructor:

public MyPagerAdapter(FragmentManager fm, int behaviour) {
    super(fm, behaviour);
}

like this :

MyPagerAdapter myPagerAdapter = new MyPagerAdapter(getChildFragmentManager(), FragmentStatePagerAdapter.BEHAVIOR_RESUME_ONLY_CURRENT_FRAGMENT);