The difference between appcompatactivity, actionbaractivity, fragmentactivity, and activity

Source: Internet
Author: User

 Packagecom.chy.myapplication;Importandroid.support.v7.app.AppCompatActivity;ImportAndroid.os.Bundle;/** Support V4 fragmentactivity compatible 2.x mode using fragment* V7 appcompatactivity Compatible with 2.x mode using fragment and actionbar,actionbaractivity are appcompatactivity obsolete products * If more than 3.0 directly inherit activity, you can use fragment and Actionbar*/ Public classMainactivityextendsappcompatactivity {@Overrideprotected voidonCreate (Bundle savedinstancestate) {Super. OnCreate (savedinstancestate);    Setcontentview (R.layout.activity_main); }}

After the Activity has developed to 3.0 (presumably), you can use fragment, but support V4 provides 1.6~3.0 fragment compatibility, so if you need to use a compatible version of fragment, you need to inherit V4 provides the fragmentactivity.
After a little bit of time, the 3.0 (presumably) Actionbar is also supported, this time in support V7, if you need to use a compatible version of Actionbar, inherit The actionbaractivity provided by V7 (which is inherited fragmentactivity).
And then the end of last year to this year, 5.0 provides a lot of new things, so support V7 also updated, appeared appcompatactivity, specific features please find out for yourself.

=============================================================================================================== =================================================
The following information is from Googlehttp://stackoverflow.com/questions/31297246/ Activity-appcompatactivity-fragmentactivity-and-actionbaractivity-when-tous

 ======================================================================================================== ===============================

activity  is The base class of all other activities, I don ' t think it'll be deprecated. The relationship among them is:

Activity<<<FragmentActivity<<<AppCompatActivity<<<ActionBarActivity

' <<< ' means inheritance here. The reference saidActionBarActivityis deprecated, useAppCompatActivityinstead.

so Basically, Using appcompatactivity  is always the right choise. The differences between them:

  • Activityis the basic one.
  • Based onActivity,FragmentActivityProvides the ability to useFragment.
  • Based onFragmentActivity,AppCompatActivityProvides features toActionBar

The difference between appcompatactivity, actionbaractivity, fragmentactivity, and activity

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.