// A request code is a unique value for returning activities
private static final int REQUEST_CODE_NEXT_ACTIVITY = 1234;
protected void startNextActivity() {
// Intents need a context, so give this current activity as the context
Intent nextActivityIntent = new Intent(this, NextActivity.class);
startActivityForResult(nextActivityResult, REQUEST_CODE_NEXT_ACTIVITY);
}
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
switch (requestCode) {
case REQUEST_CODE_NEXT_ACTIVITY:
if (resultCode == RESULT_OK) {
// This means our Activity returned successfully. For now, Toast this text.
// This just creates a simple pop-up message on the screen.
Toast.makeText(this, "Result OK!", Toast.LENGTH_SHORT).show();
}
return;
}
super.onActivityResult(requestCode, resultCode, data);
}
Activity结束时返回数据
public static final String activityResultString = "activityResultString";
/*
* On completion, place the object ID in the intent and finish with OK.
* @param returnObject that was processed
*/
private void onActivityResult(Object returnObject) {
Intent data = new Intent();
if (returnObject != null) {
data.putExtra(activityResultString, returnObject.uniqueId);
}