0% found this document useful (0 votes)
14 views6 pages

AAd Exp 5

The document outlines the creation of an Android application that utilizes Intents to pass data between two activities. It includes XML layout files for the main and second activities, along with Java code for handling user input and displaying received text. The application features an EditText for user input and a Button to initiate the transition to the second activity where the input is displayed.

Uploaded by

229x1a33b3
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)
14 views6 pages

AAd Exp 5

The document outlines the creation of an Android application that utilizes Intents to pass data between two activities. It includes XML layout files for the main and second activities, along with Java code for handling user input and displaying received text. The application features an EditText for user input and a Button to initiate the transition to the second activity where the input is displayed.

Uploaded by

229x1a33b3
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/ 6

Exp No.

: 05 Title : Android Application to create page using Intent Date:

Aim: Design an android application to create page using Intent and one Button and pass the
Values from one Activity to second Activity
activity_main.xml:

<?xml version="1.0" encoding="utf-8"?>


<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:padding="20dp">

<EditText
android:id="@+id/editText"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Enter text" />

<Button
android:id="@+id/button"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Send to Second Activity" />

</LinearLayout>

Activity_second.xml:

<?xml version="1.0" encoding="utf-8"?>


<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:padding="20dp">

<TextView
android:id="@+id/textView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Received Text Will Appear Here"
android:textSize="18sp" />

</LinearLayout>

Main_Activity.java:

package com.example.myapplication_5;

229X1A33B3
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import androidx.appcompat.app.AppCompatActivity;

public class MainActivity extends AppCompatActivity {


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

EditText editText = findViewById(R.id.editText);


Button button = findViewById(R.id.button);

button.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
String message = editText.getText().toString();
Intent intent = new Intent(MainActivity.this, SecondActivity.class);
intent.putExtra("message_key", message);
startActivity(intent);
}
});
}
}

Second_Activity.java:

package com.example.myapplication_5;

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

public class SecondActivity extends AppCompatActivity {


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

TextView textView = findViewById(R.id.textView);

// Retrieve data from Intent


String receivedMessage = getIntent().getStringExtra("message_key");

textView.setText(receivedMessage);
}
}

AndroidManifest.xml:

229X1A33B3
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools">

<application
android:allowBackup="true"
android:dataExtractionRules="@xml/data_extraction_rules"
android:fullBackupContent="@xml/backup_rules"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/Theme.MyApplication_5"
tools:targetApi="31">
<activity
android:name=".MainActivity"
android:exported="true">
<intent-filter>
<action android:name="android.intent.action.MAIN" />

<category android:name="android.intent.category.LAUNCHER" />


</intent-filter>
</activity>

<activity android:name=".SecondActivity"/>
</application>

229X1A33B3
</manifest>

229X1A33B3
229X1A33B3
229X1A33B3

You might also like