You are on page 1of 1

IT1918

Hands-on Activity
Understanding the Activity Life Cycle
Objectives:

At the end of the exercise, the students should be able to:


 create an app that demonstrates the life cycle of an activity.

Software Requirements:
 Android Studio 3.3 or higher
 Java Development Kit (JDK) 8
 Internet Connection

Procedure:
1. Create a folder named LastName_FirstName in your local drive. (ex. Reyes_Mark)
2. Create a new project. Name the app LifeCycle.
3. The onCreate() method is already provided upon creating a new project. Add a toast to show that
this method is invoked. See sample statement below.
Toast.makeText(getApplicationContext(), "Created!", Toast.LENGTH_SHORT).show();

4. Launch the application to check if the toast will appear. If there is no existing Android Virtual Device
(AVD) or emulator, create one by going to Tools > Android > AVD Manager.
5. Define the other methods to exhibit the different phases of the life cycle of an activity. All methods
should be protected, void and with empty parameters. See sample below.

protected void onStart() {


super.onStart();
//Toast statement here

The app functions correctly if:


• Upon launching the app for the first time, the toasts for these callback methods should appear in
order: onCreate(), onStart(), onResume().
• Once the Back button is pressed, the toasts for these callback methods should appear in order:
onPause(), onStop(), onDestroy().
• Once the Home button is pressed, the toast for onPause() should appear followed by onStop().
• Upon returning to the app, the toasts for these callback methods should appear in order:
onRestart(), onStart(), onResume().

03 Hands-on Activity 1 *Property of STI


Page 1 of 1

You might also like