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()
Basically, the difference is that Fragment's now have their own internal FragmentManager that can handle Fragments.
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.
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/else
ing a lot of code with version checks.
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