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設(shè)置成singleTask后 前一個activity(B)如果用startActivityForResult來啟動這個Activity(B)那么 A的onActivityResult會提前調(diào)用
解決辦法
啟動activity A時設(shè)置flag
intent.addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP|Intent.FLAG_ACTIVITY_CLEAR_TOP);
FLAG_ACTIVITY_CLEAR_TOP
如果在ABCD的堆棧狀態(tài)下将硝,以該標識啟動B民假,則會銷毀CD嵌赠,且B也是重新創(chuàng)建的(與singleTask有區(qū)別)动看,如果配合FLAG_ACTIVITY_SINGLE_TOP握截,則就會成為singleTask的模式