Difference between AppCompatActivity and Activity

Ho Ming Tam picture Ho Ming Tam · Jun 21, 2016 · Viewed 12.3k times · Source

I am trying to add menu in my application which I found, when it works if it extends AppCompatActivity, but not if it extends Activity. Is it menu is not anything available in Activity? People say Activity is basic where AppCompatActivity is something developed later, is there any good reason I should use Activity instead of AppCompatActivity? As AppCompatActivity is the default but in my learning it recommended be to choose Activity, but I found problem in creating the menu (action bar), please help!

Answer

Dylan picture Dylan · Dec 20, 2019

AppCompatActivity is a class from v7 Appcompat library. This is a compatibility library that back ports some features of recent versions of Android to older devices.

It enables the use of the ActionBar and Material Design specific implementations like the Toolbar for older devices using versions of Android as old as Android 2.1 (API level 7). So if your app's minSdkVersion is a version that does not support the new features in newer APIs you can use the support library to enable those features. If you use support library ,you have to have all your activities extend AppCompatActivity instead of the Activity base class.