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.
当一个activity(A) launchMode设置成singleTask后 前一个activity(B)如果用startActivityForResult来启动这个Activity(B)那么 A的onActivityResult会提前调用
解决办法
启动activity A时设置flag
intent.addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP|Intent.FLAG_ACTIVITY_CLEAR_TOP);
FLAG_ACTIVITY_CLEAR_TOP
如果在ABCD的堆栈状态下,以该标识启动B,则会销毁CD,且B也是重新创建的(与singleTask有区别),如果配合FLAG_ACTIVITY_SINGLE_TOP,则就会成为singleTask的模式