Several ways of transmitting values between Android Acitivity (^_^)

Source: Internet
Author: User

For the development of the app, the transmission of data is certainly indispensable, in fact, the essence of the app is to present the data.

Good

Way One Intent.putextra (Tag,data);

The application scenario is for transmitting a single data, but only between two activity.

Issue Sendactivity

Intent intent=new Intent (sendactivity.this,receiveactivity.class);

Intent.putextra (Tag,data);

StartActivity (Intent);

Receive Receiveactivity

Under the OnCreate () method of receiveactivity

String name=getintent (). Getintextra (TAG);

Note: TAG is a string flag

Data can be a string, Int,bool, and so on.

Mode two Intent.putextras (Bundle);

Application scenario pairs with multiple data and only between two activity.

Issue Sendactivity

Intent intent=new Intent (sendactivity.this,receiveactivity.class);

Bundle Bundle=new Bundle ();

Bundle.putstring ("Data One", data i );

Bundle.putstring ("Data Two", data two );

Bundle.putstring ("Data three", Data III );

。。。。

Intent.putextras (bundle);

StartActivity (Intent);

Receive Receiveactivity

Data one =this.getintent (). Getextras (). getString ("Data One");

Data two =this.getintent (). Getextras (). getString ("Data II");

Data three =this.getintent (). Getextras (). getString ("Data Three");

。。。。

Note Bundle is an object that encapsulates data, and I don't know how you understand it, so I understand that it can encapsulate many types.

Way three Application

Scenario pairs with multiple data or but individual data can be defined according to their own requirements

The Android:name attribute of the Applicaion node to Androidmanifest.xml is required plus the application class name.

Several ways of transmitting values between Android Acitivity (^_^)

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.