AAd Exp 5
AAd Exp 5
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:
<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:
<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;
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;
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" />
<activity android:name=".SecondActivity"/>
</application>
229X1A33B3
</manifest>
229X1A33B3
229X1A33B3
229X1A33B3