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

AndroidAndroid FragmentsAndroid Activity

Android Problem Overview


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?

Android Solutions


Solution 1 - Android

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

Solution 2 - Android

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

Solution 3 - Android

For people trying to make this work with Google Maps SDK see https://stackoverflow.com/questions/17042459/getfragmentmanager-with-api8 and remember to update your layout file too!

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionSkiView Question on Stackoverflow
Solution 1 - AndroidKaloerView Answer on Stackoverflow
Solution 2 - AndroidziedmazView Answer on Stackoverflow
Solution 3 - AndroidshamView Answer on Stackoverflow