我正在尝试打开我的应用程序,具体取决于输入的URL,但在某些情况下,它尝试同时执行多个活动,是否有任何方法可以限制此操作,以便在尝试执行时不执行MainAction另一个?,基本上我的清单就像这样
主要活动
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
<intent-filter android:autoVerify="true">
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<data android:scheme="http" />
<data android:scheme="https" />
<data android:host="www.test.com" />
<data android:host="m.test.com" />
</intent-filter>
<intent-filter android:autoVerify="true">
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<data
android:host="home"
android:scheme="testapp" />
</intent-filter>
</activity>
详情活动
<activity
android:name=".DetailActivity"
android:label="@string/title_activity_detail"
android:launchMode="singleInstance"
android:theme="@style/AppTheme.NoActionBar">
<intent-filter android:autoVerify="true">
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<data
android:host="detail"
android:scheme="testapp" />
</intent-filter>
<intent-filter android:autoVerify="true">
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<data android:scheme="http" />
<data android:scheme="https" />
<data android:host="www.test.com" />
<data android:host="m.test.com" />
<data android:pathPrefix="/homes"/>
</intent-filter>
</activity>
问题是,当我尝试打开像“http://www.test.com/homes”这样的链接时,会发生这种情况:
答案 0 :(得分:0)
您的DetailActivity应声明如下,不需要意图过滤器。
<activity
android:name=".DetailActivity"
android:label="@string/title_activity_detail"
android:theme="@style/AppTheme.NoActionBar">
</activity>
答案 1 :(得分:0)
重要的是MainActivity的launchMode
您应该阅读:https://developer.android.com/guide/topics/manifest/activity-element.html#lmode