Difference between LifecycleActivity, Activity, ActionbarActivity, and AppCompactActivity?

In Android, the main difference between the extension Lifecycler Activity, Activity, ActionBarActivity and AppCompactActivity? How do these classes differ from each other in terms of use?

+66
android android-activity android-actionbar android-fragments
Apr 15 '14 at 16:33
source share
5 answers
  • the ActionBarActivity extension gives you an ActionBar at every API level> = 7
  • By expanding Activity , you can avoid adding additional projects / libraries to your project, but you do not have enough ActionBar at api levels below 11

edit : Details:

ActionBarActivity is part of the Support Library . Support libraries are used to provide newer features on older platforms. For example, an ActionBar was introduced in API 11 and, by default, is part of the Activity (depending on the topic actually). In contrast, older platforms do not have an ActionBar . Thus, the support library adds a child class Activity ( ActionBarActivity ), which provides the functionality of ActionBar and ui

edit2 : update April 2015 - it looks like ActionBarActivity deprecated in revision 22.1.0 the support library. AppCompatActivity .

edit3: Aug 2017 Update - LifecycleActivity is LifecycleOwner , but:

“Because architecture components are in the alpha stage, AppCompatActivity fragments and Classes cannot implement it (because we cannot add a dependency on a stable component to an unstable API). Until the Lifecycle is stable, the LifecycleActivity and LifecycleFragment classes are for convenience. After the Lifecycles project released , fragments and actions of the support library The LifecycleOwner interface; LifecycleActivity and LifecycleFragment will be deprecated at that time. "

(copied from architecture guide)

+79
Apr 15 '14 at 17:16
source share

If you look carefully, you will see it.

 public class ActionBarActivity extends FragmentActivity implements ActionBarDrawerToggle.DelegateProvider TaskStackBuilder.SupportParentable 

Here you can read about FragmentActivity: http://developer.android.com/reference/android/support/v4/app/FragmentActivity.html

And the differences between Activity and FragmentActivity: The difference between Activity and FragmentActivity

In addition, there are several new themes for the actionBar style ... https://developer.android.com/training/basics/actionbar/styling.html

Actionbar is represented at API level 11. com.android.support:appcompat-v7:+ is a support library that allows you to have an ActionBar in your application for devices running Android 3.0 or lower. So, if you need an action bar below api level 11, your activity should expand ActionBarActivity.

If you target api level 11 or higher, you do not need to extend the ActionBarActivity and reference the AppCompat. You can simply extend the Activity and you will have actionabr by default.

The default project for Android Studio includes it automatically depending on and extends ActionbarActivity instead of Activity to use it.

+7
Apr 15 '14 at 4:55
source share

ActionBarActivity or SupportActionBarActivity have additional methods and properties that are not part of the general Activity . for example, methods for adding tabs are present in ActionBarActivity , and not in general Activity .

The main difference is that you are not getting an ActionBar for the general Activity .

+4
Apr 15 '14 at 16:51
source share

ActionBarActivity has more support libraries and better use of the newer themes available from api 11.

"In its main form, the action bar displays the title for the action and the application icon on the left. Even in this simple form, the action bar is useful for all actions to inform users of where they are, and maintain consistent identification for your application."

+1
Apr 15 '14 at 16:53
source share

You are using the Android support library. When you go to Actionbaractivity. therefore use of the support library - your application can be approved for the maximum number of devices. The support library gives your application the power of backward compatibility. Actionbaractivity gives you a mulitiple function such as Actionbardrawer toggle etc. There are more support libraries available. see this link .. and share with friends ... https://developer.android.com/tools/support-library/index.html

+1
Dec 29 '15 at 1:13
source share



All Articles