
+ --------------------------------------------------------------+         
|   this code is for image passing-message-through-intents.png  |
|                                                               |
+ --------------------------------------------------------------+ 
right click on com.example.ExplicitIntents (inside java folder (1st folder)) -> new ->activity -> empty activity (name as MainActivity2.kt)


=================================================
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="16dp">

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

    <EditText
        android:id="@+id/emailEt"
        android:hint="Enter Email"
        android:inputType="textEmailAddress"
        android:layout_width="match_parent"
        android:layout_height="wrap_content" />

    <EditText
        android:id="@+id/phoneEt"
        android:hint="Enter Phone"
        android:inputType="phone"
        android:layout_width="match_parent"
        android:layout_height="wrap_content" />

    <Button
        android:id="@+id/saveBtn"
        android:text="SAVE"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content" />

</LinearLayout>


=================================================
MainActivity.kt
=================================================


package com.example.cie3_passing_messages_through_intents

import android.app.Activity
import android.content.Intent
import android.os.Bundle
import android.widget.Button
import android.widget.EditText

class MainActivity : Activity() {
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_main)

        val nameEt = findViewById<EditText>(R.id.nameEt)
        val emailEt = findViewById<EditText>(R.id.emailEt)
        val phoneEt = findViewById<EditText>(R.id.phoneEt)
        val saveBtn = findViewById<Button>(R.id.saveBtn)

        saveBtn.setOnClickListener {
            val name = nameEt.text.toString()
            val email = emailEt.text.toString()
            val phone = phoneEt.text.toString()

            val intent = Intent(this, MainActivity2::class.java)
            intent.putExtra("Name", name)
            intent.putExtra("Email", email)
            intent.putExtra("Phone", phone)
            startActivity(intent)
        }
    }
}


=================================================
activity_main2.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="16dp">

    <TextView
        android:id="@+id/resultTv"
        android:textSize="20sp"
        android:textStyle="bold"
        android:textColor="#000000"
        android:layout_width="match_parent"
        android:layout_height="wrap_content" />

</LinearLayout>


=================================================
MainActivity2.kt
=================================================


package com.example.cie3_passing_messages_through_intents

import android.app.Activity
import android.os.Bundle
import android.widget.TextView

class MainActivity2 : Activity() {
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_main2)

        val name = intent.getStringExtra("Name")
        val email = intent.getStringExtra("Email")
        val phone = intent.getStringExtra("Phone")

        val resultTv = findViewById<TextView>(R.id.resultTv)
        resultTv.text = "Name: $name\nEmail: $email\nPhone: $phone"
    }
}