onActivityResult在setResult之前被调用

今天遇到个奇葩事,onActivityResult在setResult之前就被调用了,一开始我还以为是我的逻辑写错了,仔细看了一下,再调试了一下,发现逻辑并没有错,这下郁闷了!是个啥问题呢,百度一搜,结果没有这方面的信息,百度一下,你就知道成了百度一下,你就不知道啦。 还是用强大的Google吧!Google之后终于在almight stackOverflow上看到有人问过这个问题,最好的是有个vote88的回答,牛人是这样解释的:
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 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.
然后我看了一下AndroidManifest.xml,同伴真是将Activity设置成了: android:launchMode="singleTask",立马改成singleTop,一试果然成功,用singleInstance好像也会出现这个问题。 具体讨论可以去看看: http://stackoverflow.com/questions/3354955/onactivityresult-called-prematurely

你可能感兴趣的:(setResult)