

Full Stack Development with React & Node JS (Live).Data Structure & Algorithm Classes (Live).The AppCompatActivity class lets you use up-to-date Android app features such as the app bar and Material Design, while still enabling your app to be compatible with devices running older versions of Android. When you create a new project in Android Studio and choose the Backwards Compatibility (AppCompat) option, the MainActivity is, by default, a subclass of the AppCompatActivity class. When you create a new project for your app, or add a new Activity to your app by choosing File > New > Activity, the template automatically performs the steps listed above.

Declare the new Activity in the AndroidManifest.xml file.Implement a basic UI for the Activity in an XML layout file.

To implement an Activity in your app, do the following:

You learn more about the activity lifecycle in a later chapter. The activity lifecycle is the set of states an Activity can be in: when the activity is first created, when it's stopped or resumed, and when the system destroys it. When an activity is stopped because a new activity starts, the first activity is notified by way of the activity lifecycle callback methods. When the user is done with the current activity and presses the Back button, the activity is popped from the stack and destroyed, and the previous activity resumes. Each activity can start other activities to perform different actions.Įach time a new activity starts, the previous activity is stopped, but the system preserves the activity in a stack (the "back stack"). The user sees the main activity when they launch the app for the first time. Typically, one Activity in an app is specified as the "main" activity, for example MainActivity. For example, a messaging app could start an activity in a camera app to take a picture, then start an activity in an email app to let the user share the picture in email. This enables your app to start an activity in another app, and it enables other apps to start activities in your app (if your app allows this). Your app is probably a collection of activities that you create yourself, or that you reuse from other apps.Īlthough the activities in your app work with each other to form a cohesive user experience, each activity is independent of the others. For example, an email app might have one activity that shows a list of new emails, another activity to compose an email, and another activity for reading individual messages. You also learn about using an Intent to communicate from one activity to another.Īn activity represents a single screen in your app with an interface the user can interact with. In this chapter you learn about the Activity class, the major building block of your app's user interface (UI). Passing data from one Activity to another.Starting an Activity with an explicit Intent.Lesson 3: Testing, debugging, and using support libraries
