

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.


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
