When should I use getFragmentManager() when showing DialogFragments, and when should I use getSupportFragmentManager()?
Currently, I am showing my DialogFragments as follows:
myDialogFragment.show(getFragmentManager(), "My Dialog Fragment");
Basically, the difference is that Fragment's now have their own internal FragmentManager that can handle Fragments.
getSupportFragmentManager and getChildFragmentManager FragmentManager is class provided by the framework which is used to create transactions for adding, removing or replacing fragments. getSupportFragmentManager is associated with Activity consider it as a FragmentManager for your Activity .
FragmentManager is the class responsible for performing actions on your app's fragments, such as adding, removing, or replacing them, and adding them to the back stack.
Android OS provides a back stack function for Activity, it also provides the back stack function for Fragment. If you add one Fragment into the back stack, when you press the android device back menu, you can find the Fragment that is saved in the back stack popup.
If you are using API >= 14, then use getFragmentManager()
and while using Support Package you have to use getSupportFragmentManager()
For Example Android Support Package v4 or v13.
When you are using android.support.v4.app.FragmentManager
then you should use getSupportFragmentManager()
and if you are using android.app.FragmentManager
then use getFragmentManager()
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With