How to fix android.support.v7.actionbaractivity is deprecated

How to fix android.support.v7.actionbaractivity is deprecated

In this short android example tutorial we are going to learn how to solve the android.support.v7.actionbaractivity is deprecated. If you are using Android Studio as an IDE for android application development, you will encounter this problem with android SDK version 22 and above.

This is because the ActionBarActivity class has been deprecated and Android Studio has yet to change the default Parent Activity class from ActionBarActivity to AppCompatActivity.

This is an excerpt from Stakeoverflow The new version of ActionBarActivity (the one extending AppCompatActivity class) is a safe to use backward compatibility class. Deprecation of ActionBarActivity is just a hint for you to use new AppCompatActivity directly.

AppCompatActivity is a new, more generic implementation which uses AppCompatDelegate class internally.

Regarding AppCompatDelegate, it allows you to have new tinted widgets in an activity, which is neither AppCompatActivity nor ActionBarActivity.

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”.

Below is a diagram that illustrate what we are talking about.

How to fix android.support.v7.actionbaractivity is deprecated

When we change the parent Activity class to AppCompatActivity the error message will disappear. The image is as shown below.

actionbartwo

To read more about this, check out the android developer blog here.

OTHER INTERESTING POSTS:

Add a Comment