Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using getFragmentManager() vs getSupportFragmentManager()?

Tags:

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");
like image 430
COBOL Avatar asked Aug 14 '14 10:08

COBOL


People also ask

What is difference between getSupportFragmentManager vs getFragmentManager?

Basically, the difference is that Fragment's now have their own internal FragmentManager that can handle Fragments.

What is the use of getSupportFragmentManager?

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 .

What is the purpose of using the FragmentManager class?

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.

What is backstack in Fragment?

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.


2 Answers

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.

like image 199
Itzik Samara Avatar answered Sep 25 '22 13:09

Itzik Samara


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().

like image 21
Chintan Shah Avatar answered Sep 21 '22 13:09

Chintan Shah