有一个Activity,叫A,在这个Activity种请求其他页面叫做BActivity里的内容,所有发了个Intent: startActivityForResult已经调好的程序,后来在不经意间,把A设置了个单实例android:launchMode="singleInstance"之后 startActivityForResult就再也不好用了。通过log可以看到, intent发出以后,3ms时间就会在A的onActivitResult中收到返回消息。当然返回的消息是不正确的啦。去掉A的单实例,就好了。请问,这是为什么呢,单实例为啥会影响到startActivityForResult工作不正常了呢。
我的android系统是4.2

解决方案 »

  1.   

    当你把Aactivity设置成“singleInstance"模式以后,该activity就会有一个独享的任务栈,当它一旦被创建就不会重新创建,当它启动Bactivity后,Bactivity可能需要返回给Aactivity,但是此时Aactivity不会重新创建,不会执行回调,所以不好用了。
      

  2.   

    非常感谢你的指点,如此我就明白。为了证实这一点,我按照你的提示去查看了startActivityForResult的文档,真有这样的一段说明如下:
    Note that this method should only be used with Intent protocols that are defined to return a result. In other protocols (such as ACTION_MAIN or ACTION_VIEW), you may not get the result when you expect. For example, if the activity you are launching uses the singleTask launch mode, it will not run in your task and thus you will immediately receive a cancel result.
    跟我遇到的情况一模一样。