Difference between extending LifecycleActivity,Activity,ActionbarActivity & AppCompactActivity?

前端 未结 5 555
夕颜
夕颜 2020-11-28 02:57

In Android what is the main difference between extending Lifecycler Activity, Activity,ActionBarActivity & AppCompactActivity? How do these classes differ from each othe

5条回答
  •  悲哀的现实
    2020-11-28 03:45

    If you look carefully, you will see this

    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 differences between Activity and FragmentActivity: Difference between Activity and FragmentActivity

    Also, there are some new themes for styling actionBar... https://developer.android.com/training/basics/actionbar/styling.html

    Actionbar is introduced in API level 11. com.android.support:appcompat-v7:+ is a support library which allows you to have an ActionBar in your app for devices running on Android 3.0 or below. So, if you need actionbar below api level 11 your Activity needs to extend ActionBarActivity.

    If you are targetting api level 11 and above then you don't need to extend ActionBarActivity and reference AppCompat. You can simply extend Activity and you will have actionabr by default.

    Android Studio default project includes it automatically in dependencies and extends ActionbarActivity instead of Activity in order to use it.

提交回复
热议问题