1. Transfer data to an activity down
Activity1
1Button button=(Button) Findviewbyid (r.id.button1);2Button.setonclicklistener (NewOnclicklistener () {3 4 @Override5 Public voidOnClick (View v) {6Intent intent=NewIntent ("1111111111111111111");7Intent.addcategory ("Android.intent.category.MY_CATEGORY");8Intent.putextra ("AAA", "This is a message");9Startactivityforresult (Intent, 0x11);Ten } One});
Activity2
1 Intent intent=getintent (); 2 String Data=intent.getstringextra ("AAA"); 3 Toast.maketext (Activity2. This, data, Toast.length_short). Show ();
2. Return data to the previous activity
Activity2, button implementation returns to Activity1
1Button jumpbutton=(Button) Findviewbyid (R.id.jumpbutton);2Jumpbutton.setonclicklistener (NewOnclicklistener () {3 @Override4 Public voidOnClick (View v) {5Intent intent=NewIntent ();6Intent.putextra ("xxx", "This is second activity data!");7 Setresult (result_ok,intent);8 finish ();9 }Ten});
Activity1
Rewrite Onactivityresult ()
1 @Override2 protected voidOnactivityresult (intRequestcode,intResultCode, Intent data) {4 Super. Onactivityresult (Requestcode, ResultCode, data);5 if(requestcode==0x11) {6 if(resultcode==RESULT_OK) {7Returndata=data.getstringextra ("xxx");8 }9 } Ten}
Android Development: Pass data to the next activity, return data to the previous activity