Data transfer between activity in Android Ngti

Source: Internet
Author: User

In development, we often use the activity, then since the use of activity, it is inevitable to pass data between the two activity. Here we first talk about the principle, look at the code and examples.

Situation A: We need to start and pass data from Activity_1 to activity_2,activity_2 only to receive data from Activity_1, but not for other operations.

Case B: We need to start activity_2 from Activity_1, and want Activity_2 to pass the data to Activity_1 when it is destroyed.

First of all, let's say a.

Situation A is relatively simple, in fact, activity_1 use Intent's Putextra () method to carry the data, and then activity_2 through the intent () method to obtain Getextra passed over the data.

Situation B is a little more troublesome, but it is also very simple. is to use the Startactivityforresult () method to start Activity_2, and then activity_2 use the intent and Setresult () methods to transfer data to activity_1, and finally, activity_ 1 receive activity_2 Data via callback method Onactivityresult ().

Data transfer between activity in Android Ngti

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.