Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What should my activity extend when application's minSdkVersion is 21?

I am quite new to Android and Android Studio. I have created a new project and I have specified the minSdkVersion as 21 and target to 23.

After AS is done with creating the activity I see that MainActivity is extending AppCompatActivity by default.

I read about AppCompatActivity here

It says that it is the Base class for activities that use the support library action bar features.

Now my question is:

  1. Since my app's minSdkVersion is 21 why do I need my activity to extend AppCompatActivity?
  2. Why does AS make my activity extend AppCompatActivity by default?

  3. Is it necessary for my activity to extend AppCompatActivity or just extending Activity is enough considering my minSdkVerion?

  4. What would I miss if my actvity don't extend AppCompatActivity?

Any explanation would be very helpful. Thanks

like image 918
Nongthonbam Tonthoi Avatar asked Apr 28 '16 06:04

Nongthonbam Tonthoi


People also ask

What is extend activity?

Extension activities concentrates on putting across in an understandable manner new ideas and improved technologies of practical utility to the rural, tribal and urban privileged and underprivileged people. It enables us to use the newly acquired knowledge and skills to improve their general standard of living.

What is extend in Android?

Extensions provide a means of associating additional attributes with users or public keys and for managing a certification hierarchy. The extension format also allows communities to define private extensions to carry information unique to those communities.

What is an activity in Android?

An activity provides the window in which the app draws its UI. This window typically fills the screen, but may be smaller than the screen and float on top of other windows. Generally, one activity implements one screen in an app.

What is the extension of the main activity file in Android Studio?

The activity is a Java class, and the layout is an XML file, so the names we've given here will create a Java class file called MainActivity. java and an XML file called activity_main. xml. When you click on the Finish button, Android Studio will build your app.


Video Answer


1 Answers

I think you should extend AppCompatActivity if you are using action bar

Read more here

Beginning with Android 3.0 (API level 11), all activities that use the default theme have an ActionBar as an app bar. However, app bar features have gradually been added to the native ActionBar over various Android releases. As a result, the native ActionBar behaves differently depending on what version of the Android system a device may be using. By contrast, the most recent features are added to the support library's version of Toolbar, and they are available on any device that can use the support library.

For this reason, you should use the support library's Toolbar class to implement your activities' app bars. Using the support library's toolbar helps ensure that your app will have consistent behavior across the widest range of devices. For example, the Toolbar widget provides a material design experience on devices running Android 2.1 (API level 7) or later, but the native action bar doesn't support material design unless the device is running Android 5.0 (API level 21) or later.

like image 118
Abhishek Sinha Avatar answered Oct 24 '22 09:10

Abhishek Sinha