0% found this document useful (0 votes)
33 views

Assignment# 2: Riphah International University

The document provides an assignment for a mobile application development class. Students are asked to create an Android application with one activity and override all lifecycle methods studied in class. They must execute the app and observe which methods are called during different events, like pressing the back button. The document includes sample code showing how to override the lifecycle methods. It also gives an example of the methods called when launching the activity and pressing back. Students are tasked with considering other use cases to fully understand the activity lifecycle.

Uploaded by

Aqib Sherazi
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
33 views

Assignment# 2: Riphah International University

The document provides an assignment for a mobile application development class. Students are asked to create an Android application with one activity and override all lifecycle methods studied in class. They must execute the app and observe which methods are called during different events, like pressing the back button. The document includes sample code showing how to override the lifecycle methods. It also gives an example of the methods called when launching the activity and pressing back. Students are tasked with considering other use cases to fully understand the activity lifecycle.

Uploaded by

Aqib Sherazi
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 2

Riphah International University

Department of Software Engineering


Faculty of Computing

Mobile Application Development


Spring 2020

Assignment# 2
Date: 04/03/2020 Deadline: 09/03/2020

Q: Create an android application with only one activity, override all lifecycle methods
studied in the class. Then you must execute the application and try different cases to
observe which of the lifecycle methods are being called.
i.e., When we press back button, which of the lifecycle methods are being called?

Note: You can use Log class to print the debugging messages and observe them using
Logcat tool provided within Android Studio.

Solution:

Code:
public class ExampleActivity extends Activity {

@Override

public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState);

// The activity is being created.

@Override

protected void onStart() { super.onStart();

// The activity is about to become visible.

@Override

protected void onResume() { super.onResume();

// The activity has become visible (it is now "resumed").

@Override

protected void onPause() { super.onPause();

// Another activity is taking focus (this activity is about to be "paused").

@Override

protected void onStop() { super.onStop();

// The activity is no longer visible (it is now "stopped")

}
Riphah International University
Department of Software Engineering
Faculty of Computing

Example Case: Pressing Back Button and Coming back to the Activity.

When activity is launched for the first time, the methods called are
1. onCreate()
2. onStart()
3. onResume()

When back button is pressed while activity is running, the methods called are
4. onPause()
5. onStop()
6. onDestroy()

When activity is launched again.


7. onCreate()

Now, it is your task to think about rest of the cases.

_________________________END_____________________________

You might also like