(iii) Transfer of parameters between pages

Source: Internet
Author: User

First, page jump

1. No return value

Open Aty1

// Jump Aty1 Intent i=New Intent (mainactivity.  this, Aty1. class ); // Open startactivity (i);

Close Aty1

Finish ();

2, there is a return value of

Open Aty1 and pass in a string

PrivateButton btnStartAty1; PrivateTextView tvout; @Overrideprotected voidonCreate (Bundle savedinstancestate) {Super. OnCreate (savedinstancestate);        Setcontentview (R.layout.activity_main); BtnStartAty1=(Button) Findviewbyid (r.id.btnstartaty1); Tvout=(TextView) Findviewbyid (r.id.tvout); Btnstartaty1.setonclicklistener (NewView.onclicklistener () {@Override Public voidOnClick (view view) {Intent I=NewIntent (mainactivity. This, Aty1.class); //Passing StringsI.putextra ("txt", "adkj"); //open activity and receive the returned valueStartactivityforresult (i,0);    }        }); } @Overrideprotected voidOnactivityresult (intRequestcode,intResultCode, Intent data) {        //Receive StringString Result=data.getstringextra ("Result");        Tvout.settext (result); Super. Onactivityresult (Requestcode, ResultCode, data); }

Aty1 return information

PrivateButton btnclose; PrivateTextView tvout; protected voidonCreate (Bundle savedinstancestate) {Super. OnCreate (savedinstancestate);        Setcontentview (r.layout.aty1); Btnclose=(Button) Findviewbyid (r.id.btnclose); Btnclose.setonclicklistener (NewView.onclicklistener () {@Override Public voidOnClick (view view) {Intent I=NewIntent (); I.putextra ("Result", "Hello Mainactiviy"); //Send return valueSetresult (0, i);            Finish ();        }        }); Tvout=(TextView) Findviewbyid (r.id.tvout); Tvout.settext (Getintent (). Getstringextra ("TXT")); }

Second, the parameter transfer

1, Method one

// Jump Aty1 Intent i=New Intent (mainactivity.  this, Aty1. class ); // Pass parameter i.putextra ("txt", "adkj"); // Open startactivity (i);

Receive parameters

Getintent (). Getstringextra ("TXT")

2. Method Two

Intent i=New Intent (mainactivity.  this, Aty1. class ); Bundle Data=new  bundle ();d ata.putstring ("txt", "Hello Aty1"); I.putextras (data); StartActivity (i);

Receive parameters

Bundle data=getintent (). Getextras (); String txt=data.getstring ("txt");

(iii) Transfer of parameters between pages

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.