今天项目中遇到一个bug,从A activity跳转到B activity再返回时,A activity中onactivityresult没有执行,查半天资料,终于解决!
查看startActivityForResult的源码:
<p>Note that this method should only be used with Intent protocols * that are defined to return a result. In other protocols (such as * {@link Intent#ACTION_MAIN} or {@link Intent#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. 意思就是说,startactivityforresukt只能用在显示调用中,一些隐式调用,如调用系统的功能,不能得到返回,所以不能用 startactivityforresult。而且,调用者或者传递者的activity launchermode都不能为singleTask,只能用默认的启动模式 否则,onActivityResult会在startActivityForResult后立即调用。 详细资料可以参考http://blog.sina.com.cn/s/blog_5da93c8f0101gzf5.html