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:
Java class extends AppcompatActivity
, and
Java class extends Activity
, and
Java class extends ActionBarActivity
.
If someone give a clear definition, I will definitely tick the answer as accepted for my question.
ActionBarActivity
gives you the ActionBar
s functionality on every API level >= 7Activity
you can avoid adding additional projects/libraries to your project but you'll lack the ActionBar
on api levels below 11ActionBarActivity
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
ActionBarActivity
(the one extending AppCompatActivity
class) is a safe to use backward compatibility class. Its deprecation is just a hint for you to use new AppCompatActivity
directly instead. AppCompatActivity
is a new, more generic implementation which uses AppCompatDelegate
class internally.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".