Multiple onActivityResult for 1 Activity

In your startActivityForResult, don’t use 0’s on both calls… use different numbers like 0 & 1… then you can implement a switch in your onActivityResult method with the requestCode. If the requestCode = 0 then the first method has returned, if it is 1, then the second has returned. This should be the same for more calls.

public void onActivityResult(int requestCode, int resultCode, Intent intent){
    switch(requestCode){
        case 0: // Do your stuff here...
        break;
        case 1: // Do your other stuff here...
        break;
        case etc:
        break;
    }
}

The calls should be something like this then:
(For the first time)

startActivityForResult(intent1, 0);

(For the second time)

startActivityForResult(intent2, 1);

(for the third time)

startActivityForResult(intent3, 2);

(for the nth time)

startActivityForResult(intentn, n - 1);

Or, you could declare static int values to use, instead of the more unrecognisable int values.

Leave a Comment