

When it comes to common mistakes people make when they are using ViewPager inside a Fragment, they often pass getSupportFragmentManager, which is a fragment manager for an activity, and it causes issues such as memory leaks or ViewPager not updating properly. Here is the official link for this for better understanding.

Whenever you are ViewPager inside a fragment you will use getChildFragmentManager.Įxample: FragmentManager cfManager=getChildFragmentManager() viewPagerAdapter = new ViewPagerAdapter(cfManager) getChildFragmentManager is associated with fragments.getInstance() bottomSheetDialog.show(getSupportFragmentManager(), "Custom Bottom Sheet") So whenever you are using ViewPager, BottomSheetFragment, and DialogFragment in an activity you will use getSupportFragmentManagerĮxample: BottomDialogFragment bottomSheetDialog = BottomDialogFragment. Consider it as a FragmentManager for your activity. getSupportFragmentManager is associated with an activity.GetSupportFragmentManager and getChildFragmentManagerįragmentManager is class provided by the framework which is used to create transactions for adding, removing or replacing fragments.
