Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

getSupportFragmentManager() versus getFragmentManager() in android 3.0+

In the documentation for android.support.v4.app.FragmentManager:

"Static library support version of the framework's FragmentManager. Used to write apps that run on platforms prior to Android 3.0. When running on Android 3.0 or above, this implementation is still used; it does not try to switch to the framework's implementation. See the framework SDK documentation for a class overview."

So, do I need to do a check at runtime and use the appropriate FragmentManager for the android version the app is running on? i.e. call getFragmentManager() if on android 3.0+ instead of getSupportFragmentManager()

like image 766
user1159819 Avatar asked Sep 12 '12 02:09

user1159819


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.

When use getSupportFragmentManager?

If you are using support Packages in your project or app, then you have to use getSupportFragmentManager because that is how you will return the fragmentManager for interacting with fragments associated with this activity. In the other hand, if you are not, then you can use getFragmentManager.


1 Answers

There's nothing wrong with using getSupportFragmentManager() on Android 3.0+ as long as you have the support library imported. If you want to use getFragmentManager() for SDKs 11+, go for it; just keep in mind that you may be if/elseing a lot of code with version checks.

like image 91
Cat Avatar answered Oct 22 '22 05:10

Cat