androidandroid-activityandroid-actionbarextendsappcompatactivity

Difference between "Java class extends" "AppcompatActivity" vs "Activity" vs "ActionBar" in Android?


Android - I am going to develop an app which API is between API 15 and the latest API.
But I have one question regarding "Java class extends".

What is the difference between:

  1. Java class extends AppcompatActivity, and

  2. Java class extends Activity, and

  3. Java class extends ActionBarActivity.

If someone give a clear definition, I will definitely tick the answer as accepted for my question.


Solution

  • 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

    For instance, you inherit an activity from an external library, which, in turn, does not inherit from AppCompatActivity but you want this activity to have tinted materials widgets (views). To make it happen you need to create an instance of AppCompatDelegate inside your activity, override methods of that activity like addContentView(), setContentView() etc. (see AppCompatDelegate javadoc for the full list of methods), and inside those overridden methods forward the calls to inner AppCompatDelegate instance. AppCompatDelegate will do the rest and your "old-fashion" activity will be "materialized".

    Source: this and this.