[Android] data transmission between activities

Source: Internet
Author: User

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.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.