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
Activity
,FragmentActivity
provides the ability to useFragment
. - Based on
FragmentActivity
,AppCompatActivity
provides features toActionBar