Android enables pages to jump and pass parameters to each other

Source: Internet
Author: User

First, for the two pages of mutual value, jump when we use Startactivityforresult (intent,0), rather than startactivity (intent) This method

In the first page, write in the button that triggers the jump.

            Intent intent=New Intent (mainactivity.  this, secondactivity. class );             // Pass the value in the text box            Intent.putextra ("name", Text.gettext (). toString ());             // In order to accept the value in the secondactivity, do not startacitivity (intent)            Startactivityforresult (intent,1000);                          // Animated Descriptions            between two animations Overridependingtransition (R.anim.enter, r.anim.exit);

Two, in the second person activity to return data using Setresult method, and in the final call to finish ()

Intent Intent =getintent (); Bundle Bundle=Intent.getextras (); String Name=bundle.getstring ("name"); Secondactivity. This. Settitle ("Welcome" +Name); Bt1.setonclicklistener (NewView.onclicklistener () {@Override Public voidOnClick (View arg0) {//TODO auto-generated Method StubIntent intent=NewIntent (secondactivity. This, Mainactivity.class); //Pass the value in the text boxIntent.putextra ("Backname", Text.gettext (). toString ()); Setresult ( 1001, intent); //End the life of the current Activity objectfinish (); //SecondActivity.this.finish ();            }        }); 

Third, rewrite the Onactivityresult method on the first page to receive data from the second activity callback

@Override//rewrite the Onacitivityresultprotected voidOnactivityresult (intRequestcode,intResultCode, Intent data) {    Super. Onactivityresult (Requestcode, ResultCode, data); if(Requestcode = = && ResultCode = = 1001) {String result= Data.getstringextra ("Backname"); Mainactivity. This. Settitle ("received" +result); Toast.maketext (Getapplicationcontext (),Cancel, Toast.length_long). Show (); }    Else if(Requestcode = = && ResultCode = = 1002) {String result= Data.getstringextra ("Backname"); Mainactivity. This. Settitle ("received" +result); Toast.maketext (Getapplicationcontext (),Determine, Toast.length_short). Show (); }}

Source Address: http://download.csdn.net/download/qq_34793108/9836860

Android enables pages to jump and pass parameters to each other

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.