Difference between extending LifecycleActivity,Activity,ActionbarActivity & AppCompactActivity?

Umer Kiani picture Umer Kiani · Apr 15, 2014 · Viewed 57.2k times · Source

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?

Answer

stan0 picture stan0 · Apr 15, 2014
  • 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)