ذكري المظهر:سلوك SingleTop مع مرشحات الأغراض المتعددة
-
21-12-2019 - |
سؤال
أنا أعاني من السلوك الغريب التالي لأنشطة SingleTop.
لقد حددت بعض مرشحات النية في هذا النشاط:
<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 of the DashboardActivity أتحقق من الإجراء المناسب:
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
في وضع التشغيل، فإنه يطلق نشاطًا جديدًا، ولكنه يمرر الهدف الصحيح.لا بد لي من استخدام نفس مثيل النشاط، لذلك singleTop
, singleTask
أو singleInstance
يجب أن يقوم بهذه المهمة.لكنني لا أعرف ما الخطأ الذي يحدث هنا.يساعد!
المحلول
Intent.ACTION_VIEW.equals(intent.getAction())
ومن أين تأتي هذه النية؟من أجل التقاط النية الجديدة يجب عليك استخدامهاonNewIntent().
لا تنتمي إلى StackOverflow