I want to transfer data between two activities using Android int.

Asked 1 years ago, Updated 1 years ago, 84 views

I'm using the Intent function to make a simple product calculator application

This calculator uses a total of two activities In Activity 1, enter the quantity of two items with buttons (four buttons from 1 to 4 per item), and press the RESULT button to move the quantity to Activity 2.

In Activity 2, the price of two items is just entered into EditText, and when you press the CALCULATE button, the quantity received from Activity 1 is multiplied by the price to obtain the total price. And when you press the RETURN button, the total is passed to Activity 1 and it ends.

It is a program that returns to Activity 1 and outputs the total amount received from Activity 2.

I used startActivityForResult(), onActivityResult() to run this program, but it didn't work well, so I have a question here TT..

In Activity 1, it works well to press the button to receive the quantity, but if you press the RESULT button, the application turns off. I would really appreciate it if you could advise me on what I made a mistake.

(Delete Source After Resolution) -> The error occurred because the variable was declared incorrectly in the activity, not the content issue.It was a simple problem.

intent java android

2022-09-22 19:38

1 Answers

It is difficult to identify the exact problem because there is no log.

Code to be invoked at the end of Activity_2

Intent outIntent = newIntent();
outIntent.putExtra("Totals", String.valueOf(totals));
setResult(RESULT_OK,outIntent);
finish();

You can change it to that


2022-09-22 19:38

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.