我一直在尝试在一个react-native应用程序中进行深层链接,并试图在导航器内直接打开一个屏幕。我使用了 react-native-deep-linking
和 react-navigation
作为库。同时还使用了嵌套导航器。深度链接可以正常工作,除了我在使用的 android:launchMode
属性。
这是我对每个的 android:launchMode
选项。
android:launchMode="standard"
- 应用程序使用深层链接打开,但会打开一个全新的应用程序。android:launchMode="singleTask"
- 应用程序使用深层链接打开。如果我使用其他链接打开应用程序。应用程序出现在前台,但它直接指向前一个链接。android:launchMode="singleTop"
- 应用程序使用深层链接打开,但打开了一个全新的应用程序。android:launchMode="singleInstance"
- 应用程序使用深层链接打开,但打开了一个全新的应用程序。如果我删除了 android:launchMode
属性,同样会发生与 "标准 "模式相同的情况,因为它是默认的。
我可以用什么方案来解决这个问题?有没有什么@覆盖,我可以在主活动里面做?
下面是我的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>
不知道是否还相关,但可能对以后的人有帮助。
原因是,当活动处于标准模式以外的任何模式时,从后台重新打开应用程序不会替换用于从被杀状态启动应用程序的原始意图。相反,这些新的意图将被引导到的 onNewIntent(Intent intent)
方法。在那里,你可以调用 setIntent(Intent intent)
以便用新的意图替换活动的意图。
你可以在你的MainActivity中重写这个方法。(请注意,当在React中重写这个方法时,我必须把它变成一个新的方法。public
而不是 protected
就像我通常在Android中做的那样。还不知道为什么)
在这里阅读更多 - https:/developer.android.comreferenceandroidappActivity#onNewIntent(android.content.Intent)