Android:複数の意図フィルタを使用したシングルトップの動作
-
21-12-2019 - |
質問
シングルトップ活動の次の奇妙な行動に苦しんでいます。
その活性にいくつかの意図フィルターを定義しました:
<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>
.
このコードはアクティビティを開始するべきです:
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);
}
});
.
ダッシュボーダーアクトティーの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
アクションを取得します。singleTop
起動モードを削除すると、新しいアクティビティが起動されますが、正しい意図を渡します。私はアクティビティの同じインスタンスを使用する必要があります。しかし、私はここで何が間違っているのかわかりません。助けて!
解決
Intent.ACTION_VIEW.equals(intent.getAction())
.
この意図はどこから来たのですか?あなたが使用しなければならない新しい意図を捕まえるために onnewintent()。
所属していません StackOverflow