Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Difference between AppCompatActivity and Activity

I am trying to add a menu in my application. It works if it extends AppCompatActivity, but not if it extends Activity. Is the menu not 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? AppCompatActivity is the default but in my learning it was recommended to choose Activity, but I encountered the problem in creating the menu (action bar). Please help!

like image 417
Ho Ming Tam Avatar asked Jun 20 '16 22:06

Ho Ming Tam


1 Answers

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.

like image 112
Dylan Avatar answered Oct 11 '22 01:10

Dylan