Lab 3a

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 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