Difference between extending LifecycleActivity,Activity,ActionbarActivity & AppCompactActivity?

AndroidAndroid FragmentsAndroid ActivityAndroid Actionbar

Android Problem Overview


In Android what is the main difference between extending Lifecycler Activity, Activity,ActionBarActivity & AppCompactActivity? How do these classes differ from each other in terms of usage?

Android Solutions


Solution 1 - Android

  • extending ActionBarActivity gives you the ActionBars functionality on every API level >= 7
  • by extending Activity you can avoid adding additional projects/libraries to your project but you'll lack the ActionBar on api levels below 11

edit: More details:

ActionBarActivity is part of the Support Library. Support libraries are used to deliver newer features on older platforms. For example the ActionBar was introduced in API 11 and is part of the Activity by default (depending on the theme actually). In contrast there is no ActionBar on the older platforms. So the support library adds a child class of Activity (ActionBarActivity) that provides the ActionBar's functionality and ui

edit2: Update April 2015 - it looks like the ActionBarActivityis deprecated in revision 22.1.0 of the Support Library. AppCompatActivity should be used instead.

edit3: Update Aug 2017 - LifecycleActivity is a LifecycleOwner but:

> "Since the Architecture Components are in alpha stage, Fragment and > AppCompatActivity classes cannot implement it (because we cannot add a > dependency from a stable component to an unstable API). Until > Lifecycle is stable, LifecycleActivity and LifecycleFragment classes > are provided for convenience. After the Lifecycles project is > released, support library fragments and activities will implement the > LifecycleOwner interface; LifecycleActivity and LifecycleFragment will > be deprecated at that time."

(copied from the Architecture Components guideline)

Solution 2 - Android

If you look carefully, you will see this

public class ActionBarActivity extends FragmentActivity
implements ActionBarDrawerToggle.DelegateProvider TaskStackBuilder.SupportParentable

Here you can read about FragmentActivity: http://developer.android.com/reference/android/support/v4/app/FragmentActivity.html

And differences between Activity and FragmentActivity: https://stackoverflow.com/questions/10477997/difference-between-activity-and-fragmentactivity

Also, there are some new themes for styling actionBar... https://developer.android.com/training/basics/actionbar/styling.html

Actionbar is introduced in API level 11. com.android.support:appcompat-v7:+ is a support library which allows you to have an ActionBar in your app for devices running on Android 3.0 or below. So, if you need actionbar below api level 11 your Activity needs to extend ActionBarActivity.

If you are targetting api level 11 and above then you don't need to extend ActionBarActivity and reference AppCompat. You can simply extend Activity and you will have actionabr by default.

Android Studio default project includes it automatically in dependencies and extends ActionbarActivity instead of Activity in order to use it.

Solution 3 - Android

The ActionBarActivity or the SupportActionBarActivity have additional methods and properties that are not in a generic Activity. for example methods for adding tabs are present in the ActionBarActivity and not in a generic Activity.

The major difference being you don't get an ActionBar on a generic Activity.

Solution 4 - Android

ActionBarActivity just has more support libraries and better usage of the newer themes available from api 11.

"In its most basic form, the action bar displays the title for the activity and the app icon on the left. Even in this simple form, the action bar is useful for all activities to inform users about where they are and to maintain a consistent identity for your app."

Solution 5 - Android

You are using Android support library When you come to to the Actionbaractivity . so the uses of Support library is your application can be suport for maximum number of devices. Support library gives to your application the power of Backward compatibilty. Actionbaractivity gives you the mulitiple feature like Actionbardrawer toggle etc.. there are more support libraries available. see this link .. and share to your friends...https://developer.android.com/tools/support-library/index.html

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
QuestionUmer KianiView Question on Stackoverflow
Solution 1 - Androidstan0View Answer on Stackoverflow
Solution 2 - Androidvanste25View Answer on Stackoverflow
Solution 3 - Androiddanny117View Answer on Stackoverflow
Solution 4 - AndroidMatthew CarnaghiView Answer on Stackoverflow
Solution 5 - AndroidNoorulView Answer on Stackoverflow