8

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

user1159819
  • 1,549
  • 4
  • 16
  • 29

3 Answers3

12

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.

Cat
  • 66,919
  • 24
  • 133
  • 141
  • any ideas what the difference between these two managers are? Advantages/disadvantages? – user1159819 Sep 14 '12 at 00:55
  • The support library is designed to exactly emulate the functionality. There are a few tiny minor differences about halfway through [the support library docs](http://developer.android.com/tools/extras/support-library.html). – Cat Sep 14 '12 at 16:59
6

If you are using API >= 14, then use getFragmentManager(). If you want compatibility with devices below API 14 then you can use getSupportFragmentManager(). Therefore, getSupportFragmentManager() is used to deliver newer features to older platforms.

Kaveesh Kanwal
  • 1,753
  • 17
  • 16
0

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. It only depends on what you are using in your app.

Red M
  • 2,609
  • 3
  • 30
  • 50