onActivityResult() called prematurely

This is fixed by changing the launch mode to singleTop:

    <activity
        android:name=".MainActivity"
        android:launchMode="singleTop">

There’s a bug / feature (?) in Android, which immediately reports result (which has not been set yet) for Activity, declared as singleTask (despite the fact that the activity continues to run). If we change launchMode of the parent activity from singleTask to singleTop, everything works as expected – result is reported only after the activity is finished. While this behavior has certain explanation (only one singleTask activity can exist and there can happen multiple waiters for it), this is still a not logical restriction for me.

Leave a Comment