Professional Documents
Culture Documents
Name Roll: Chavda Vijay Pravinbhai 20MCA012 "
Name Roll: Chavda Vijay Pravinbhai 20MCA012 "
</LinearLayout>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Answer"
android:id="@+id/textans"
android:gravity="center"
android:layout_margin="25dp"
android:textStyle="bold"
android:textColor="#F44336"
android:textSize="35dp"
/>
</LinearLayout>
Activity_activityintenetsecond.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context=".Activutyintentsecond">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Answer"
android:id="@+id/textresult"
android:gravity="center"
android:layout_margin="25dp"
android:textStyle="bold"
android:textColor="#F44336"
android:textSize="35dp"
/>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/button11"
android:layout_gravity="center"
android:text="Submit"/>
</LinearLayout>
Activityintent.java
package com.example.helloworld;
import androidx.activity.result.ActivityResult;
import androidx.activity.result.ActivityResultCallback;
import androidx.activity.result.ActivityResultLauncher;
import androidx.activity.result.contract.ActivityResultContracts;
import androidx.appcompat.app.AppCompatActivity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_intent);
ed1 = findViewById(R.id.edit1);
ed2 = findViewById(R.id.edit2);
gotosecond = findViewById(R.id.button1);
choiceactivty = findViewById(R.id.button2);
answer = findViewById(R.id.textans);
gotosecond.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent intent = new
Intent(ActivityIntent.this,Activutyintentsecond.class);
}
});
activityResultLauncher = registerForActivityResult(new
ActivityResultContracts.StartActivityForResult(), new
ActivityResultCallback<ActivityResult>() {
@Override
public void onActivityResult(ActivityResult result) {
if(result.getResultCode()==RESULT_OK)
{
Intent intent = result.getData();
answer.setText(""+intent.getIntExtra("Sum",-111));
}
}
});
}
}
Activityintenetsecond.java
package com.example.helloworld;
import androidx.appcompat.app.AppCompatActivity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;
TextView result;
Button submit;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_activutyintentsecond);
result = findViewById(R.id.textresult);
submit = findViewById(R.id.button11);
submit.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
finish();
}
});
}
}