Requirements: Jumps from firstactivity to Secondactivity, operates in secondactivity, and returns to Firstactivity.
The main code in firstactivity:
private static final int request_code = 1;
private static final int result_code = 101;
Triggering events
public void Gotosencond () {
Intent intent=new Intent (this,secondactivity.class);
Startactivityforresult (Intent, Request_code);
}
The second parameter in the Onactivityresult () method is the key returned by the secondactivity, and the third parameter is the value of the key that Secondactivity returns.
@Override
protected void Onactivityresult (int requestcode, int resultcode, Intent data) {
if (Requestcode==request_code) {
if (Resultcode==result_code) {
String Result=data.getstringextra ("second");//Gets the contents of the secondactivity returned
Textview.settext (result);
}
}
Super.onactivityresult (Requestcode, ResultCode, data);
}
Code in the Secondactivity class:
final int result_code=101;
public void CloseButton (view view) {
Intent intent=new Intent ();
Intent.putextra ("Second", "I am second!");
Setresult (Result_code, intent);
Finish ();
}
Onactivityresult () in Android gets the return value