Difference between Activity and FragmentActivity

AndroidAndroid FragmentsAndroid Support-LibraryAndroid Fragmentactivity

Android Problem Overview


I was working on fragments and came across two things Activity and FragmentActivity which are used several times. I want to know that is there any difference between these two, because when I changed Activity with FragmentActivity, it had no effect on the app.

Android Solutions


Solution 1 - Android

A FragmentActivity is a subclass of Activity that was built for the Android Support Package.

The FragmentActivity class adds a couple new methods to ensure compatibility with older versions of Android, but other than that, there really isn't much of a difference between the two. Just make sure you change all calls to getLoaderManager() and getFragmentManager() to getSupportLoaderManager() and getSupportFragmentManager() respectively.

Solution 2 - Android

FragmentActivity is part of the support library, while Activity is the framework's default class. They are functionally equivalent.

You should always use FragmentActivity and android.support.v4.app.Fragment instead of the platform default Activity and android.app.Fragment classes. Using the platform defaults mean that you are relying on whatever implementation of fragments is used in the device you are running on. These are often multiple years old, and contain bugs that have since been fixed in the support library.

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
QuestionRookieView Question on Stackoverflow
Solution 1 - AndroidAlex LockwoodView Answer on Stackoverflow
Solution 2 - AndroidSamuel PeterView Answer on Stackoverflow