How can I access getSupportFragmentManager() in a fragment?
You can directly call
getParentFragmentManager()
to get the fragment manager. Note that getFragmentManager() also works but has been marked as deprecated.
All you need to do is using
getFragmentManager()
method on your fragment. It will give you the support fragment manager, when you used it while adding this fragment.
Fragment Documentation
Simply get it like this -
getFragmentManager() // This will also give you the SupportFragmentManager or FragmentManager based on which Fragment class you have extended - android.support.v4.app.Fragment OR android.app.Fragment.
OR
getActivity().getSupportFragmentManager();
in your Fragment's onActivityCreated() method and any method that is being called after onActivityCreated().
Kotlin users try this answer
(activity as AppCompatActivity).supportFragmentManager
if you have this problem and are on api level 21+ do this:
map = ((SupportMapFragment) getChildFragmentManager().findFragmentById(R.id.map))
.getMap();
this will get the map when used inside of a fragment.