Home » Android » Android Compatibility Package doesn't include Activity.getFragmentManager()

Android Compatibility Package doesn't include Activity.getFragmentManager()

Posted by: admin November 29, 2017 Leave a comment

Questions:

I started trying to add fragments to my Android app, which is based on 2.1, using the Android Compatibility Package that just came out on March 3rd. I included the library into my project, and started moving the code from my Activity-based class to a Fragment-based one, but I noticed that the Fragment examples from Google seem to rely on the fact that the Activity class in 3.0 (Honeycomb) has the new method getFragmentManager(). It seems to be an integral hook into the Fragment system.

I’ve tried to look inside the Compatibility Package library for some included Activity implementation that has getFragmentManager(), but I can’t find it. Does anyone know where I can find getFragmentManager() so I can include Fragments for Honeycomb compatibility, or if not do you know how I can include Fragments without using a FragmentManager?

Answers:

You will need to extend FragmentActivity instead of the normal Activity. Then you will be able to call getSupportFragmentManager() which works the same way as getFragmentManager().

Questions:
Answers:

You have only to change your Android Target to API Level = 12

Questions:
Answers:

For people trying to make this work with Google Maps SDK see getFragmentManager with API8 and remember to update your layout file too!