I have previously reproduced an article about data transmission between activities. I always feel that I have not gained much from copying and pasting and it seems quite uncomfortable. I am determined to rewrite it. The previous article will be directly replaced with the original article link.
We often encounter this situation. When we use an activity, the code is too bloated and the interface is not very beautiful. At this time, data transmission between activities becomes particularly important. Next I will use an instance to introduce data transmission between different activities.
We enter two numbers in the first activity and then output the results in the second activity. The main code of the two activities is as follows:
Num1 = Integer. parseInt (input1.getText (). toString (); <br/> num2 = Integer. parseInt (input2.getText (). toString (); <br/> sum = num1 + num2; <br/> Intent intent = new Intent (this, output. class); <br/> Bundle bundle = new Bundle (); <br/> bundle. putInt ("num1", num1); <br/> bundle. putInt ("num2", num2); <br/> bundle. putInt ("sum", sum); <br/> intent. putExtras (bundle); <br/> startActivity (intent );
Bundle bundle = this. getIntent (). getExtras (); <br/> int num1 = bundle. getInt ("num1"); <br/> int num2 = bundle. getInt ("num2"); <br/> int num3 = bundle. getInt ("sum ");
In this way, data can be transmitted between two activities.