Android - startActivityForResult 立即触发 onActivityResult [英] Android - startActivityForResult immediately triggering onActivityResult
问题描述
我正在使用调用 startActivityForResult(intent, ACTIVITY_TYPE)
从我的应用程序中的主要 Activity 启动 Activity,并且它们都在工作,但只有一个.
I am launching activities from the main activity in my app using the call startActivityForResult(intent, ACTIVITY_TYPE)
, and they are all working but one.
调用此函数时,会根据需要启动活动,但在日志中我可以看到 onActivityResult()
立即被触发.活动出现但 RESULT_CANCELED
立即返回到 onActivityResult()
.
This one, when called, launches the activity as desired, but in the log I can see that onActivityResult()
is immediately being triggered. The activity shows up but RESULT_CANCELED
is immediately returned to onActivityResult()
.
然后我与 Activity 交互,按下一个调用 finish()
的按钮,这次没有调用 onActivityResult()
(因为显然结果已经返回).
I then interact with the activity, press a button which calls finish()
, and onActivityResult()
is not called this time (because apparently a result has already been returned).
这对任何人都有意义吗?以前有人见过这种行为吗?
Does this make sense to anyone? Has anyone seen this behavior before?
推荐答案
如果您的 Activity 作为 singleInstance
或 启动,则不能使用
startActivityForResult()
代码>单个任务代码>.standard
或 singleTop
启动模式将解决问题.
You can't use startActivityForResult()
if your activity is being launched as a singleInstance
or singleTask
. standard
or singleTop
launch mode will fix the problem.
这篇关于Android - startActivityForResult 立即触发 onActivityResult的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!