gpt4 book ai didi

android - React Native 深度链接和 android :launchMode problem

转载 作者:行者123 更新时间:2023-12-04 15:39:38 27 4
gpt4 key购买 nike

我一直在尝试在 react-native 应用程序中进行深层链接,并尝试在导航器中直接打开屏幕。我使用 react-native-deep-linkingreact-navigation 作为库。还使用嵌套导航器。深层链接工作正常,但我在 android:launchMode 属性方面遇到了一些问题。

这是我为每个 android:launchMode 选项获得的结果。

  • android:launchMode="standard" - 应用程序使用深层链接打开,但会打开一个全新的应用程序。
  • android:launchMode="singleTask" - 应用程序使用深层链接打开。如果我使用另一个链接打开应用程序。应用程序出现在前台,但它指向上一个链接。
  • android:launchMode="singleTop" - 应用程序使用深层链接打开,但会打开一个全新的应用程序。
  • android:launchMode="singleInstance" - 应用程序使用深层链接打开,但会打开一个全新的应用程序。

如果我删除 android:launchMode 属性,同样的事情会发生在“标准”模式下,因为它是默认模式。

我可以使用什么选项来解决这个问题?我可以在主要 Activity 中执行任何 @override 吗?

下面是我的AndroidManifest.xml

<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
<uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW"/>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>

<application
android:name=".MainApplication"
android:label="@string/app_name"
android:icon="@mipmap/ic_launcher"
android:roundIcon="@mipmap/ic_launcher_round"
android:allowBackup="false"
android:theme="@style/AppTheme">
<activity
android:name=".MainActivity"
android:launchMode="singleTask"
android:label="@string/app_name"
android:screenOrientation="portrait"
android:configChanges="keyboard|keyboardHidden|orientation|screenSize"
android:windowSoftInputMode="adjustResize">
<intent-filter>
<action android:name="android.intent.action.MAIN"/>
<category android:name="android.intent.category.LAUNCHER"/>
</intent-filter>
<intent-filter>
<action android:name="android.intent.action.VIEW"/>
<category android:name="android.intent.category.DEFAULT"/>
<category android:name="android.intent.category.BROWSABLE"/>
<category android:name="android.intent.category.VIEW"/>

<data android:scheme="https" android:host="*.myapplive.com" android:pathPrefix="/"/>
<data android:scheme="https" android:host="*.myapp.com" android:pathPrefix="/"/>
</intent-filter>
</activity>
<activity android:name="com.facebook.react.devsupport.DevSettingsActivity"/>
</application>

最佳答案

不确定是否仍然相关,但将来可能会对某人有所帮助。

原因是,当 Activity 处于标准以外的任何模式时,从后台重新打开应用程序不会取代用于从终止状态启动应用程序的原始 Intent 。相反,这些新 Intent 将被定向到 onNewIntent(Intent intent) 方法。在那里,您可以调用 setIntent(Intent intent) 以用新的 intent 替换 Activity 的 intent。

您可以在 MainActivity 中覆盖此方法。 (请注意,在 React 中重写此方法时,我必须将其设置为 public 而不是 protected ,就像我通常在 Android 中所做的那样。还不确定为什么)

在这里阅读更多 - https://developer.android.com/reference/android/app/Activity#onNewIntent(android.content.Intent)

关于android - React Native 深度链接和 android :launchMode problem,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58317376/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com