首页 > 解决方案 > 在 Ionic Cordova 平台插件 exitApp() 之后总是 RESULT_CANCELED

问题描述

我在 App A 中使用动作意图来启动 App B 的 MainActivity。

App A 使用以下代码启动活动并接收活动结果

val webIntent = Intent("com.someAction")
                    startActivityForResult(webIntent, REQUEST_CODE)

override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
    super.onActivityResult(requestCode, resultCode, data)
    if (requestCode == REQUEST_CODE) {
        if (resultCode == RESULT_OK) {
            Log.d("DEBUG", "Aha, the transaction is done")

        } else if (resultCode == RESULT_CANCELED) {
            Log.d("DEBUG", "Hmm, something's wrong")
        }
  

App B 使用以下代码设置结果

@Override
protected void onDestroy() {
    super.onDestroy();
    if (someLogicIsTrue) {
        setResult(RESULT_OK, getIntent());
    } else {
        setResult(RESULT_CANCELED, getIntent());
    }
}

但是,无论 someLogicIsTrue 是 True 还是 False(即设置结果为 RESULT_OK),每当 App B 的 MainActivity 被销毁时,App A 总是会收到 RESULT_CANCELED。

我目前正在使用 this.platform.exitApp() 退出 App B 活动并成功返回 App A,只有结果始终为 RESULT_CANCELED。平台插件是否在偷偷摸摸地覆盖我设置的结果?如何确保将 RESULT_OK 返回给 App A?

附加信息(应用 B 的 Manifest.xml)

<activity android:configChanges="orientation|keyboardHidden|keyboard|screenSize|locale" android:label="@string/activity_name" android:launchMode="singleTask" android:name="MainActivity" android:screenOrientation="portrait" android:theme="@android:style/Theme.DeviceDefault.NoActionBar" android:windowSoftInputMode="adjustResize">
            <intent-filter android:label="@string/launcher_name">
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
            <intent-filter>
                <action android:name="com.someAction" />
                <category android:name="android.intent.category.DEFAULT" />
                <category android:name="android.intent.category.BROWSABLE" />
                <data android:mimeType="text/plain" />
            </intent-filter>
</activity>

标签: androidcordovaionic-frameworkcordova-pluginsngcordova

解决方案


推荐阅读