onActivityResult不火,如果活动的启动模式是singleInstance模式、onActivityResult、singleInstance

2023-09-12 04:16:49 作者:巛型男嗦囡丶站

我有一个活动基本上是我的主要活动,它的发射方式为单实例。但由于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 exit in the same task as the caller, hence it can't return the value to the caller.

考虑使用singleTask来代替:

Consider using singleTask instead:

singleTask

该系统在创建活动   新的任务和路线根   意图吧。然而,如果一个实例   的活性已存在,则   系统路线的意图,现有的   例如通过调用其   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.

singleInstance

同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