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