Mainactivity.java
Intent Intent = new Intent ();
Intent.putextra ("message", "the value passed to Secondactivity");
Intent.setclass (Mainactivity.this, Secondactivity.class);
/*
* If you want to start another activity and want to have a return value, you need to use the Startactivityforresult method,
* The first parameter is the intent object, and the second argument is a Requestcode value, if you have more than one button to start activity, requestcode marks the activity
*/
Startactivityforresult that each button launches (intent, 1000);
/**
* The return value of all activity objects is received by this method
* Requestcode: Represents a simultaneous value that initiates an activity requestcode past br> * ResultCode: Represents the ResultCode value of the activated activity callback value
* data: Represents the intent object returned by the startup activity
*/
@Override
protected void onactivityresult (int requestcode, int resultcode, Intent data)
{
Super . Onactivityresult (Requestcode, ResultCode, data);
if (Requestcode = = && ResultCode = = 1001)
{
String result_value = Data.getstringext RA ("result");
}
}
Secondactivity.java
Received in the OnCreate method, and can be received in other methods
String mainstring = Getintent.getstringextra ("message");
overriding return events
@Override
public boolean onKeyDown (int keycode, keyevent event) {
if (keycode = = Keyevent.keycode_back) {
Intent Intent = new Intent ();
Intent.putextra ("result", result);
/*
* Calling the Setresult method means I return the intent object to the previous activity so that the intent object can be obtained in the Onactivityresult method.
*/
Setresult (1001, intent);
return true;
}
Return Super.onkeydown (KeyCode, event);
}
Transfer and return values for Android two activity