0% found this document useful (0 votes)
100 views4 pages

Lab 3a - Android Activity Lifecycle: SKR4307-Mobile Application

This document discusses an Android activity lifecycle lab assignment. It includes the Java code for a MainActivity class that implements methods corresponding to the activity lifecycle phases like onCreate(), onStart(), onResume(), etc. Each method displays a toast notification of the current phase. It also includes the XML layout code for the activity's user interface containing a simple text view.

Uploaded by

Aisya Zuhudi
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
100 views4 pages

Lab 3a - Android Activity Lifecycle: SKR4307-Mobile Application

This document discusses an Android activity lifecycle lab assignment. It includes the Java code for a MainActivity class that implements methods corresponding to the activity lifecycle phases like onCreate(), onStart(), onResume(), etc. Each method displays a toast notification of the current phase. It also includes the XML layout code for the activity's user interface containing a simple text view.

Uploaded by

Aisya Zuhudi
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 4

SKR4307- Mobile Application

Lab 3a - Android Activity Lifecycle

By: Nurul Aisyah Binti Ahmad Zuhudi

Matric Number: 193904


MainActivity.java
package com.example.lab3a;

import android.app.Activity;
import android.os.Bundle;
import android.util.Log;
import android.widget.Toast;

public class MainActivity extends Activity {

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Toast.makeText(MainActivity.this,"ON CREATE",
Toast.LENGTH_SHORT).show();
}

@Override
protected void onStart() {
super.onStart();
Toast.makeText(MainActivity.this,"ON START",
Toast.LENGTH_SHORT).show();
}

@Override
protected void onResume() {
super.onResume();
Toast.makeText(MainActivity.this,"ON RESUME",
Toast.LENGTH_SHORT).show();

@Override
protected void onPause() {
super.onPause();
Toast.makeText(MainActivity.this,"ON PAUSE",
Toast.LENGTH_SHORT).show();

@Override
protected void onStop() {
super.onStop();
Toast.makeText(MainActivity.this,"ON STOP",
Toast.LENGTH_SHORT).show();

@Override
protected void onRestart() {
super.onRestart();
Toast.makeText(MainActivity.this,"ON RESTART",
Toast.LENGTH_SHORT).show();

@Override
protected void onDestroy() {
super.onDestroy();
Toast.makeText(MainActivity.this,"ON DESTROY",
Toast.LENGTH_SHORT).show();

}
}

activity_main.xml
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Hello World!"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent" />

</androidx.constraintlayout.widget.ConstraintLayout>
Expected Results

You might also like