Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
startActivityForResult() sample code
public class Activity2 extends AppCompatActivity {
public static final String RESULT = "result";
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_2);
Bundle bundle = getIntent().getExtras();
if (bundle != null) {
String messageFromActivity = bundle.getString(MESSAGE);
if (messageFromActivity != null && messageFromActivity.length() >= 3) {
String response = "Yes, I'm here";
Intent intent = new Intent();
intent.putExtra(RESULT, response);
setResult(RESULT_OK, intent);
finish();
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment