0% found this document useful (0 votes)
513 views3 pages

MAD Practical 17

The document contains XML and Java code for an Android application. The XML code defines the layout for an activity containing a TextView. The Java code is for a MainActivity class that implements the activity lifecycle methods like onCreate(), onStart(), onResume(), etc. and uses logs and toasts to output messages at each stage to demonstrate the lifecycle.

Uploaded by

sajid shaikh
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)
513 views3 pages

MAD Practical 17

The document contains XML and Java code for an Android application. The XML code defines the layout for an activity containing a TextView. The Java code is for a MainActivity class that implements the activity lifecycle methods like onCreate(), onStart(), onResume(), etc. and uses logs and toasts to output messages at each stage to demonstrate the lifecycle.

Uploaded by

sajid shaikh
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/ 3

Practical 17

XML Code

<?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_constraintEnd_toEndOf="parent"

app:layout_constraintStart_toStartOf="parent"

app:layout_constraintTop_toTopOf="parent" />

</androidx.constraintlayout.widget.ConstraintLayout>

Java Code

package com.example.gmail.practical17;

import androidx.appcompat.app.AppCompatActivity; import android.os.Bundle;

import android.util.Log; import android.widget.Toast;

public class MainActivity extends AppCompatActivity {

private static final String TAG=MainActivity.class.getSimpleName(); @Override


protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main); Log.d(TAG,"in onCreate");

Toast.makeText(this,"on create",Toast.LENGTH_SHORT).show();

@Override

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

Log.d(TAG,"in method onStart");

Toast.makeText(this,"on start",Toast.LENGTH_SHORT).show();

@Override

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

Log.d(TAG,"in method onResume");

Toast.makeText(this,"on Resume",Toast.LENGTH_SHORT).show();

@Override

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

Log.d(TAG,"in method onPause");

Toast.makeText(this,"on pause",Toast.LENGTH_SHORT).show();

@Override

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

Log.d(TAG,"in method onStop");

Toast.makeText(this,"on stop",Toast.LENGTH_SHORT).show();

@Override

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

Log.d(TAG,"in method onDestroy");

Toast.makeText(this,"on destroy",Toast.LENGTH_SHORT).show();

@Override
protected void onRestart() { super.onRestart();

Log.d(TAG,"in method onRestart");

Toast.makeText(this,"on Restart",Toast.LENGTH_SHORT).show();

Output

You might also like