Difference between AppCompatActivity and Activity [closed]

1

I have a little doubt what difference there is between an AppCompatActivity and an Activity when it comes to extending a class?

Thanks in advance

    
asked by Eduardo 02.05.2017 в 19:10
source

2 answers

1

AppCompatActivity: It is the super class of an activity in which it contains methods that will inherit or that can inherit from that class,

Activity: It is the view that can be given to the end user, from which they can implement the methods that exist within AppCompatActivity enter the description of the link here

    
answered by 02.05.2017 / 21:51
source
3

Basically the difference is that

AppCompatActivity

It is the base class for activities that use the action bar functions ( ActionBar ) of the support library .

Knowing that you can add a ActionBar to our activity only when running in API level 7 or higher by extending this class for your activity and setting the activity topic in Theme.AppCompat or a similar theme.

See: Android Documentation

For AppCompatActivity to work, the following steps are required:

  • Add dependency in build.gradle

    android  { 
                compileSdkVersion 25  buildToolsVersion "25.0.2"
              }
    dependencies 
              {
                compile 'com.android.support:appcompat-v7:25.2.0'
              }
    
  • The MainActivity should be declared as follows:

    public class MainActivity extends AppCompatActivity {
        // ...
    }
    
  • The theme (Theme) of the Application must be established as follows:

    <application android:theme="@style/Theme.AppCompat">

  • Activity

    An activity is a unique and focused thing that the user can do. Almost all activities interact with the user, so the class Activity is responsible for creating a window where you can place your user interface with setContentView (View) .

    While activities are often presented to the user as full-screen windows, they can also be used in other ways: as floating windows (using a theme with the set windowIsFloating ) or embedded within another activity (using ActivityGroup ). There are two methods that almost all subclasses of Activity will implement:

  • OnCreate (Bundle) is where you initialize your activity. The most important thing is that here you usually call setContentView (int) with a design resource that defines the user interface and use findViewById (int) to recover the widgets of that user interface with which you need to interact programmatically.

  • OnPause () is where it is about the user leaving their activity. More importantly, any changes made by the user must be committed at this time (usually the ContentProvider containing the data).

  • To be useful with Context.startActivity () , all activity classes must have a corresponding declaration <activity> in package AndroidManifest.xml of their package.

    Lifecycle of an Activity

    See: Android Documentation

        
    answered by 02.05.2017 в 23:13