如果活动的启动模式是 singleInstance,则 onActivityResult 不会触发 [英] onActivityResult do not fire if launch mode of activity is singleInstance

查看:25
本文介绍了如果活动的启动模式是 singleInstance,则 onActivityResult 不会触发的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个 Activity,它基本上是我的主要 Activity,它的启动模式是单实例.但由于 singleInstance,onActivityResult() 回调不会触发.如果我将清单文件中的启动模式更改为任何其他模式,它就可以正常工作.

I have an Activity which is basically my main activity and its launch mode is single instance. But because of singleInstance, the onActivityResult() callback does not fire. And if I change the launch mode in my manifest file to any other mode it works fine.

你能解释为什么这个回调不起作用吗?

Can you explain why this callback is not working?

推荐答案

我认为问题在于 singleInstance 不允许被调用者活动与调用者存在于同一任务中,因此它无法返回值给来电者.

I believe that the problem is that singleInstance doesn't let the callee activity to exist in the same task as the caller, hence it can't return the value to the caller.

考虑改用 singleTask:

Consider using singleTask instead:

单一任务

系统在新任务的根并路由意图.但是,如果一个实例的活动已经存在,系统将意图路由到现有实例通过调用其onNewIntent() 方法,而不是创建一个新的.

The system creates the activity at the root of a new task and routes the intent to it. However, if an instance of the activity already exists, the system routes the intent to existing instance through a call to its onNewIntent() method, rather than creating a new one.

单个实例

与singleTask"相同,除了系统不启动任何其他活动进入任务持有实例.活动始终是其任务的唯一成员.

Same as "singleTask", except that the system doesn't launch any other activities into the task holding the instance. The activity is always the single and only member of its task.

http://developer.android.com/guide/topics/manifest/activity-element.html

这篇关于如果活动的启动模式是 singleInstance,则 onActivityResult 不会触发的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆