Reputation: 99
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!
Upvotes: 6
Views: 14809
Reputation: 391
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.
Upvotes: 3
Reputation: 320
As this answer What's the enhancement of AppCompatActivity over ActionBarActivity? explains, unless you're targeting API levels older than 11, you should probably use AppCompatActivity. If you are however, only targeting API levels above that, you should be fine just using Activity, since the newer versions have everything you need to create the menu on the ActionBar.
Hope it helps
Upvotes: -2