zoukankan      html  css  js  c++  java
  • AppCompatActivity、ActionBarActivity、FragmentActivity和Activity的区别

    package com.chy.myapplication;
    import android.support.v7.app.AppCompatActivity;
    import android.os.Bundle;
    /*
    * support v4 FragmentActivity  兼容2.x模式下使用Fragment
    * support v7 AppCompatActivity 兼容2.x模式下使用Fragment和ActionBar,ActionBarActivity是AppCompatActivity过时产品
    * 如果3.0以上直接继承Activity,便可使用Fragment和ActionBar
    */
    public class MainActivity extends AppCompatActivity {
    @Override
        protected void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.activity_main);
        }
    }
    Activity 发展到3.0(大概)之后,可以使用fragment了,但是support v4 提供了1.6~3.0的fragment兼容,所以如果需要用兼容版的fragment,则需要继承support v4提供的FragmentActivity。
    而后一点点时间之后,3.0(大概)出现的ActionBar也被向前支持了,这次是出现在support v7里,如果需要使用兼容版的actionbar,则继承support v7提供的ActionBarActivity(它是继承FragmentActivity的)。
    再然后也就是去年年底到今年,5.0提供了很多很多新东西,于是support v7也更新了,出现了AppCompatActivity , 具体功能请自行查找。

    ================================================================================================================================================================
    以下内容来自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 will be deprecated. The relationship among them is:

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

    '<<<' means inheritance here. The reference said ActionBarActivity is deprecated, use AppCompatActivity instead.

    So basically, using AppCompatActivity is always the right choise. The differences between them:

    • Activity is the basic one.
    • Based on ActivityFragmentActivity provides the ability to use Fragment.
    • Based on FragmentActivityAppCompatActivity provides features to ActionBar
    
    
  • 相关阅读:
    Java如何编写自动售票机程序
    install windows service
    redis SERVER INSTALL WINDOWS SERVICE
    上传文件
    This problem will occur when running in 64 bit mode with the 32 bit Oracle client components installed.
    解决Uploadify上传控件加载导致的GET 404 Not Found问题
    OracleServiceORCL服务不见了怎么办
    Access to the temp directory is denied. Identity 'NT AUTHORITYNETWORK SERVICE' under which XmlSerializer is running does not have sufficient permiss
    MSSQL Server 2008 数据库安装失败
    数据库数据导出成XML文件
  • 原文地址:https://www.cnblogs.com/liaojie970/p/5799356.html
Copyright © 2011-2022 走看看