gpt4 book ai didi

Android:具有多个 Intent 过滤器的 SingleTop 行为

转载 作者:行者123 更新时间:2023-11-29 21:10:31 27 4
gpt4 key购买 nike

我正在努力应对 SingleTop Activity 的以下奇怪行为。

我在该 Activity 中定义了一些 Intent 过滤器:

<activity android:name="com.example.DashboardActivity"
android:screenOrientation="landscape"
android:launchMode="singleTop"
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<data android:scheme="video" />
<category android:name="android.intent.category.BROWSABLE"/>
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
<intent-filter>
<action android:name="android.intent.action.EDIT" />
<data android:scheme="survey" />
<category android:name="android.intent.category.BROWSABLE"/>
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
<intent-filter>
<action android:name="android.intent.action.CALL" />
<data android:scheme="call" />
<category android:name="android.intent.category.BROWSABLE"/>
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>

此代码应启动 Activity :

webView.setWebViewClient(new WebViewClient() 
{
public boolean shouldOverrideUrlLoading(WebView view, String url) {

try {
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setData(Uri.parse(url));
startActivity(intent);

return true;

} catch(ActivityNotFoundException e) {

Log.e(TAG,"Could not load url"+url);
}

return super.shouldOverrideUrlLoading(view, url);

}

});

在 DashboardActivity 的 onResume 中,我检查相应的操作:

public void onResume(){
super.onResume();
Fragment fragment = null;

if (Intent.ACTION_VIEW.equals(intent.getAction())) {

extras.putParcelable("uri", getIntent().getData());
fragment = new VideoplayerFragment();

} else {

fragment = new DashboardFragment();

}

addOrReplaceFragment(fragment, extras);
}

但是当我运行这段代码时,我总是得到 android.intent.action.MAIN Action 。如果我删除 singleTop 启动模式,它会启动一个新 Activity ,但会传递正确的 Intent 。我必须使用 Activity 的相同实例,因此 singleTopsingleTasksingleInstance 必须完成这项工作。但我不知道这里出了什么问题。帮助!

最佳答案

Intent.ACTION_VIEW.equals(intent.getAction())

这个 Intent 来自哪里?为了 catch 新的 Intent ,你必须使用 onNewIntent() .

关于Android:具有多个 Intent 过滤器的 SingleTop 行为,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23017475/

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