我试图截取点击的网址以打开我的APP
<intent-filter>
<data
android:host="myurl.open"
android:path="/import"
android:scheme="http" />
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.BROWSABLE" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
在MainActivity中
String linkClicked = getIntent().getDataString();
new AlertDialog.....
它几乎正常,但问题是:
每个新点击的链接都会打开我的应用的新实例,但我不想要这个,我希望它显示在同一个打开的实例中
示例:
点击myurl.open/import?=1
打开第一个显示用户在链接中单击的对话框的实例
点击myurl.open/import?=2
打开第一个实例并显示显示新点击的URL的对话框,但是它打开了一个新实例,所以我现在有2个正在运行的apks,如果我点击第三个链接它将打开第三个,我该怎么做它只打开相同的?
如果我再次点击相同的网址,则会打开从此网址打开的第一个实例,但它不会显示AlertDialog
答案 0 :(得分:1)
1)要打开您应用的单个实例,请在活动代码中的android:launchMode="singleTask"
中使用android:launchMode="singleInstance"
或AndroidManifest.xml
。
2)要从新意图中获取数据,只需覆盖onNewIntent()方法:
@Override
protected void onNewIntent(Intent intent) {
super.onNewIntent(intent);
setIntent(intent); // to attach the new intent to your Activity
//now getIntent() will return the last data
}