Professional Documents
Culture Documents
Mad 2.1
Mad 2.1
1. Aim:
Create an Android app that uses Intent with button to create a page and passes
values from one activity to another.
2. Objective:
The objective of an Android app that uses Intent with a button to create a page and
passes values from one activity to another could be to demonstrate and implement a
simple data communication flow between different activities within an Android
application. This type of app is commonly used to understand and showcase the
concept of passing data between different screens or pages in Android.
3. Procedure:
Step 1: Create a New Project
To create a new project in Android Studio please refer to How to Create/Start a
New Project in Android Studio. We are implementing it for both Java and Kotlin
languages.
Main Activity.java
package com.example.tryintent3;
import androidx.appcompat.app.AppCompatActivity;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main); editTextMessage
= findViewById(R.id.editTextMessage); buttonSend =
findViewById(R.id.buttonSend);
buttonSend.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
String message = editTextMessage.getText().toString();
Intent intent = new Intent(MainActivity.this,
SecondActivity.class);
intent.putExtra("MESSAGE", message);
startActivity(intent);
}
});
}
}
Second Activity.java
package com.example.tryintent3;
DEPARTMENT OF
COMPUTER SCIENCE & ENGINEERING
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;
import androidx.appcompat.app.AppCompatActivity;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_second);
textViewMessage = findViewById(R.id.textViewMessage);
buttonBack = findViewById(R.id.buttonBack);
Main Activity.xlm
<EditText
android:id="@+id/editTextMessage"
android:layout_width="match_parent"
android:layout_height="100dp"
android:hint="Enter your message" />
<Button
android:id="@+id/buttonSend"
android:layout_width="161dp"
android:layout_height="64dp"
android:layout_below="@id/editTextMessage"
android:layout_centerHorizontal="true"
android:layout_marginTop="16dp"
android:text="Send Message"
android:background="#00FF00"/>
</RelativeLayout>
Second Activity.xml
<TextView
android:id="@+id/textViewMessage"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Received Message"
android:layout_centerHorizontal="true"
android:layout_marginTop="16dp"/>
<Button
android:id="@+id/buttonBack"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Back"
android:layout_below="@id/textViewMessage"
android:layout_centerHorizontal="true"
android:layout_marginTop="16dp"/>
</RelativeLayout>
4.Output:
DEPARTMENT OF
COMPUTER SCIENCE & ENGINEERING
5.Observation /Outcome:
• Learnt about Intent in Android Development.
• Learnt about Button in Android Development.
• Learnt about Intent and Button Functionality and how to configure it.
• Learnt to build intent and button in Android device.
6.Learning Outcome:
Successfully setup Android Studio ,and creating my first intent and button in
Android studio.