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

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?

22197 次浏览

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

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

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