Murugan.P Murugan.P - 1 year ago 145
Android Question

onActivityResult called before setResult

I have a program where onActivityResult() is being called with the correct request code, and a null intent parameter And, when that activity calls setResult(),onactivityresult is not called. onActivityResult() called after startActivityForResult()

public void placeListActivity(View view) {

Intent placeListIntent = new Intent(this,
// startActivity(placeListIntent);
this.startActivityForResult(placeListIntent, 5);

protected void onActivityResult(int request, int result, Intent arg2) {
super.onActivityResult(request, result, arg2);

if (request == 5 && result == Activity.RESULT_OK) {

Second Activity:

public void onBackPressed() {



Answer Source

You are only sending resultCode so intent will be received null. send Intent with resultCode in setResult method as a second parameter. You will get that intent in first activity.

setResult method signature

Note:- When the activity's launch mode is singleTask or singleTop, the onActivityResult will be called as soon as the activity is started with a data null. To prevent this, use Intent.setFlags(0) to reset the default flags.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download