繁体   English   中英

React Native 深度链接和 android:launchMode 问题

[英]React Native deeplinking and android:launchMode problem

我一直在尝试在 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属性,同样的事情也会发生在“标准”模式下,因为它是默认模式。

我可以使用什么选项来解决此问题? 我可以在主要活动中做任何@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 处于非标准模式时,从后台重新打开应用程序不会替换用于从已终止的 state 启动应用程序的原始意图。 相反,这些新意图将被定向到onNewIntent(Intent intent)方法。 在那里,您可以调用setIntent(Intent intent)以用新的意图替换活动的意图。

您可以在 MainActivity 中覆盖此方法。 (请注意,当在 React 中覆盖此方法时,我必须将其public且不受protected ,就像我通常在 Android 中所做的那样。尚不知道为什么)

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM