如何获得startActivityForResult外部活动工作?如何获得、工作、startActivityForResult

2023-09-06 11:36:25 作者:天空是会哭的海

在搜索高低已经没有产生任何结果,我的问题。因此,我终于发布,恳求一些帮助。

Searching high and low has yielded no result for my problem. Hence I'm finally posting to plead for some assistance.

我有两个应用程序,无论是我写的。应用程序中的启动应用程序B,通过Intent.putExtra传入的参数()。这工作完全正常,当应用程序B被推出的参数是很好的传递。

I have two app, both written by me. App A launches App B, passing in parameters through Intent.putExtra(). This works perfectly fine when App B is launched the parameters are passed nicely.

不过,我无法找到一个方法来返回响应应用程序A.使用startActivityForResult()总是给我立即onActivityResult()与RESULT_CANCELED。经进一步检查,logcat的给了我一个警告,指出活动推出的一项新的任务,所以取消活动的结果。

However, I can't find a way to return a response to App A. Using startActivityForResult() always gave me immediate onActivityResult() with RESULT_CANCELED. Upon further inspection, the logcat gave me a warning stating "Activity is launching as a new task, so cancelling activity result".

我试图使附录二的活动不同的启动模式,行动过滤器(android.intent.action.PICK),但没有我不改变任何东西。

I tried making Activity of App B with different launch mode, action filters (android.intent.action.PICK), but nothing I do changed anything.

难道我试图做不可能的事?据我了解,我所试图做的应该是类似使用第三方活动回升,从设备的图片库的图片。

Am I trying to do the impossible? From what I understand, what I am attempting to do should be similar to using third-party activity to pick pictures from the device's photo gallery.

编辑:

好吧,我试图消除从b活动发射类别,但它仍然无法正常工作。这是我的活动:

Ok, I tried removing the LAUNCHER category from Activity B but it still doesn't work. Here's my activity:

<activity android:name=".${CLASSNAME}" android:label="@string/app_name" android:configChanges="mcc|mnc|locale|keyboardHidden|orientation" android:launchMode="standard">
    <intent-filter>
        <action android:name="android.intent.action.PICK" />
    </intent-filter>
</activity>

有没有人真正得到了这个工作?我开始怀疑起一个活动,是另一个应用程序永远不能返回的结果,因为它似乎它永远启动一个新的任务,不管你放在意向过滤器。

Has anybody actually got this to work? I'm beginning to suspect starting an activity that is of another app can never return results since it seems it'll always start a new task no matter what you put in the "intent-filter".

推荐答案

请确保您正在启动没有Android的活动:launchMode在其上设置的清单,并检查了android:taskAffinity不被使用。在这里看到:

Make sure that the Activity you are launching doesn't have android:launchMode set on it in the manifest and check the android:taskAffinity is not being used. See here:

http://developer.android.com/guide/主题/清单/活性element.html#AFF

请确保您使用来启动该活动的意图并没有FLAG_ACTIVITY_NEW_TASK设置就可以了。在这里看到:

Make sure that the Intent you are using to launch the activity doesn't have FLAG_ACTIVITY_NEW_TASK set on it. See here:

的http://developer.android.com/reference/android/content/Intent.html#FLAG_ACTIVITY_NEW_TASK

在特别需要注意:这个标志不能当呼叫者请求被推出活动的结果用

In particular note: "This flag can not be used when the caller is requesting a result from the activity being launched."

如果该活动正在启动,作为一个新的任务的一部分,然后Android将会立即拨打onActivityResult()与RESULT_CANCELED因为在一个任务的活动无法将结果返回给另一个任务,只有活动在同一个任务可以这样做

If the activity is being launched as part of a new task then Android will immediately call the onActivityResult() with RESULT_CANCELED because an activity in one task can't return results to another task, only activities in the same task can do so.