0% found this document useful (0 votes)
187 views7 pages

Mobile Application Development: Practical 2

This document describes a mobile application development practical project that involves navigating between two activities. The main activity contains a text view that, when clicked, launches a new intent to open the second activity. Both activities implement the various activity lifecycle callback methods like onCreate, onStart, onResume, etc. and display Toast messages to trace the lifecycle changes. The goal is to understand how to use intents to transition between activities and observe the lifecycle events.

Uploaded by

sahil patel
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)
187 views7 pages

Mobile Application Development: Practical 2

This document describes a mobile application development practical project that involves navigating between two activities. The main activity contains a text view that, when clicked, launches a new intent to open the second activity. Both activities implement the various activity lifecycle callback methods like onCreate, onStart, onResume, etc. and display Toast messages to trace the lifecycle changes. The goal is to understand how to use intents to transition between activities and observe the lifecycle events.

Uploaded by

sahil patel
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

MOBILE APPLICATION

DEVELOPMENT
Practical 2

Meet Patel
181260107059

Computer engineering class A


Sal engineering and technical institute
PRACTICAL-2
Aim-Understand use of intent and navigate from
one file to another.

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"
android:background="@android:color/holo_red_light"
tools:context=".MainActivity">

<TextView
android:id="@+id/textview"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="First activity"
android:textColor="@color/white"
android:textSize="34sp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent" />

</androidx.constraintlayout.widget.ConstraintLayout>

Main_activity.java
package com.example.madp2;

import androidx.appcompat.app.AppCompatActivity;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.TextView;
import android.widget.Toast;

public class MainActivity extends AppCompatActivity {


TextView txtv;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
txtv = findViewById(R.id.textview);

txtv.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent intent = new Intent(MainActivity.this,
secondactivity.class);
startActivity(intent);
}
});
}

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

@Override
protected void onResume() {
super.onResume();
Toast.makeText(this,"Resume",Toast.LENGTH_SHORT).show();
}

@Override
protected void onStop() {
super.onStop();
Toast.makeText(this,"Stop",Toast.LENGTH_SHORT).show();
}

@Override
protected void onPause() {
super.onPause();
Toast.makeText(this,"pause",Toast.LENGTH_SHORT).show();
}

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

@Override
protected void onDestroy() {
super.onDestroy();
Toast.makeText(this,"Destroy",Toast.LENGTH_SHORT).show();
}
}
Second_activity.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"
android:background="#E91E63"
tools:context=".secondactivity">

<TextView
android:id="@+id/textView"
android:layout_width="186dp"
android:layout_height="36dp"
android:text="Second activity"
android:textColor="@color/white"
android:textSize="24sp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
</androidx.constraintlayout.widget.ConstraintLayout>

Secondactivity.java
package com.example.androidactivitylifecycledemo;

import androidx.appcompat.app.AppCompatActivity;

import android.os.Bundle;
import android.widget.Toast;

public class secondactivity extends AppCompatActivity {

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_secondactivity);
}

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

@Override
protected void onResume() {
super.onResume();
Toast.makeText(this,"Resume",Toast.LENGTH_SHORT).show();
}

@Override
protected void onStop() {
super.onStop();
Toast.makeText(this,"Stop",Toast.LENGTH_SHORT).show();
}

@Override
protected void onPause() {
super.onPause();
Toast.makeText(this,"pause",Toast.LENGTH_SHORT).show();
}

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

@Override
protected void onDestroy() {
super.onDestroy();
Toast.makeText(this,"Destroy",Toast.LENGTH_SHORT).show();
}

}

You might also like