Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What's the enhancement of AppCompatActivity over ActionBarActivity?

People also ask

Why do we extend AppCompatActivity?

The AppCompatActivity gets improvements periodically (support library updates). The normal Activity class is static, the code was written once and never updated. So whatever the Android version, AppCompatActivity is almost always better, faster, newer.

Why do we use AppCompatActivity?

AppCompatActivity is the new way to go because the ActionBar is not encouraged anymore and you should use Toolbar instead (that's currently the ActionBar replacement). AppCompatActivity inherits from FragmentActivity so if you need to handle Fragments you can (via the Fragment Manager).

What is an AppCompatActivity?

AppCompatActivity(int contentLayoutId) Alternate constructor that can be used to provide a default layout that will be inflated as part of super. onCreate(savedInstanceState) .


As Chris wrote, new deprecated version of ActionBarActivity (the one extending AppCompatActivity class) is a safe to use backward compatibility class. Its deprecation is just a hint for you asking to use new AppCompatActivity directly instead. AppCompatActivity is a new, more generic implementation which uses AppCompatDelegate class internally.

If you start a new development, then you should rather use new AppCompatActivity class right away. If you have a chance to update your app, then replace deprecated ActionBarActivity by the new activity as well. Otherwise you can stay with deprecated activity and there will be no difference in behavior at all.

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 of those overridden methods forward the calls to the inner AppCompatDelegate instance. AppCompatDelegate will do the rest and your "old-fashion" activity will be "materialized".


It's mostly a name change: ActionBarActivity doesn't really describe everything it now does. You can safely use ActionBarActivity if you wish to. Think of it like a symlink.


The AppCompat Support Library started with humble, but important beginnings: a single consistent Action Bar for all API 7 and higher devices. In revision 21, it took on new responsibility: bringing material color palette, widget tinting, Toolbar support, and more to all API 7+ devices. With that, the name ActionBarActivity didn’t really cover the full scope of what it really did.

http://android-developers.blogspot.it/2015/04/android-support-library-221.html


AppCompatActivity was introduced into Android-SDK since the release of android support appcompat library.

AppCompatActivity is the direct child class of FragmentActivity of support v4 and the direct parent class of ActionBarActivity.

AppCompatActivity is the base class for activities that use the support library action bar features.

You can add an ActionBar to your activity when running on API level 7 or higher by extending this class for your activity and setting the activity theme to Theme.AppCompat or a similar theme.

As for support v7 appcompat library, it adds support for the Action Bar user interface design pattern. This library includes support for material design user interface implementations.

Here are a few of the key classes included in the v7 appcompat library:

  • ActionBar - Provides an implementation of the action bar user interface pattern.
  • AppCompatActivity - Adds an application activity class that can be used as a base class for activities that use the Support Library action bar implementation.
  • AppCompatDialog - Adds a dialog class that can be used as a base class for AppCompat themed dialogs.
  • ShareActionProvider - Adds support for a standardized sharing action (such as email or posting to social applications) that can be included in an action bar.

After you download the Android Support Libraries, this library is located in the /extras/android/support/v7/appcompat/ directory.


Previously the only entry point into AppCompat was through the now deprecated ActionBarActivity class. Unfortunately this forced you into using a set Activity hierarchy which made things like using PreferenceActivity impossible.

see chris banes's support-libraries-v22-1-0 for more info


The latest release of android support library, 22.1, deprecates the ActionBarActivity in favor of AppCompatActivity, which promises to bring a single consistent ActionBar for all devices starting with API Level 7 and above