MainActivity.java:

package com.example.appone;

import android.content.Intent;
import android.os.Bundle;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.EditText;
import android.widget.RadioButton;
import androidx.appcompat.app.AppCompatActivity;

public class MainActivity extends AppCompatActivity {

    EditText etName;

    RadioButton rbMale, rbFemale;

    CheckBox cbJava, cbPython, cbAndroid;

    Button btnSubmit;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        etName = findViewById(R.id.etName);
        rbMale = findViewById(R.id.rbMale);
        rbFemale = findViewById(R.id.rbFemale);
        cbJava = findViewById(R.id.cbJava);
        cbPython = findViewById(R.id.cbPython);
        cbAndroid = findViewById(R.id.cbAndroid);

        btnSubmit = findViewById(R.id.btnSubmit);
        btnSubmit.setOnClickListener(v -> {

            String name = etName.getText().toString().trim();

            if (name.isEmpty()) {
                etName.setError("Enter student name");
                etName.requestFocus();
                return;
            }
            String gender = "";

            if (rbMale.isChecked()) {
                gender = "Male";

            } else if (rbFemale.isChecked()) {
                gender = "Female";
            } else {
                gender = "Not selected";
            }
            String subjects = "";
            if (cbJava.isChecked())
                subjects += "Java, ";
            if (cbPython.isChecked())
                subjects += "Python, ";
            if (cbAndroid.isChecked())
                subjects += "Android, ";
            if (!subjects.isEmpty()) {
                subjects =
                        subjects.substring(
                                0,
                                subjects.length() - 2);
            }
            Intent intent =
                    new Intent(
                            MainActivity.this,
                            SecondActivity.class);
            intent.putExtra("name", name);
            intent.putExtra("gender", gender);
            intent.putExtra("subjects", subjects);
            startActivity(intent);
        });
    }
}


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"
    android:gravity="center_vertical">

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="STUDENT DETAILS"
        android:textSize="24sp"
        android:textStyle="bold"/>


    <EditText
        android:id="@+id/etName"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:hint="Enter Student Name"
        android:layout_marginTop="20dp"/>

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Select Gender"
        android:layout_marginTop="20dp"/>

    <RadioGroup
        android:id="@+id/radioGroup"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content">

        <RadioButton
            android:id="@+id/rbMale"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Male"/>

        <RadioButton
            android:id="@+id/rbFemale"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Female"/>
    </RadioGroup>

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Select Subjects"
        android:layout_marginTop="20dp"/>

    <CheckBox
        android:id="@+id/cbJava"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Java"/>

    <CheckBox
        android:id="@+id/cbPython"
        android:layout_width="wrap_content"


        android:layout_height="wrap_content"
        android:text="Python"/>

    <CheckBox
        android:id="@+id/cbAndroid"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Android"/>

    <Button
        android:id="@+id/btnSubmit"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="SUBMIT"
        android:layout_marginTop="20dp"/>

</LinearLayout>


SecondActivity.java:

package com.example.appone;

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

public class SecondActivity extends AppCompatActivity {

    TextView txtDetails;
    Button btnBack;

    @Override
    protected void onCreate(Bundle savedInstanceState) {

        super.onCreate(savedInstanceState);

        setContentView(R.layout.activity_second);

        txtDetails = findViewById(R.id.txtDetails);

        btnBack = findViewById(R.id.btnBack);

        String name =
                getIntent().getStringExtra("name");


        String gender =
                getIntent().getStringExtra("gender");

        String subjects =
                getIntent().getStringExtra("subjects");

        txtDetails.setText(
                "STUDENT DETAILS\n\n" +
                        "Name: " + name +
                        "\n\nGender: " + gender +
                        "\n\nSubjects: " + subjects);
        btnBack.setOnClickListener(v -> finish());

    }
}


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:gravity="center"
    android:orientation="vertical">

    <TextView
        android:id="@+id/txtDetails"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:textSize="20sp"
        android:textStyle="bold"
        android:textAlignment="center"/>

    <Button
        android:id="@+id/btnBack"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="BACK"
        android:layout_marginTop="20dp"/>

</LinearLayout>


AndroidManifest.xml:

<?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.Appone">
        <activity
            android:name=".MainActivity"
            android:exported="true"
            android:windowSoftInputMode="adjustResize">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
        <activity
            android:name=".SecondActivity"
            android:exported="false" />
    </application>
</manifest>