I\'m defining an ID for my fragment in the xml layout:
The reasons mentioned above are valid but another possible reason is that you are trying to search for the fragment while being in a fragment this also results in fragmentManager.findFragmentById
to return null. We should use childFragmentManager.findFragmentById
to find the fragment inside a fragment.
According to the official documentation.
public final androidx.fragment.app.FragmentManager getChildFragmentManager()
Return a private FragmentManager for placing and managing Fragments inside of this Fragment.