Androide:Comportamiento SingleTop con múltiples filtros de intención
-
21-12-2019 - |
Pregunta
Estoy luchando con el siguiente comportamiento extraño de las actividades de SingleTop.
He definido algunos filtros de intención en esa actividad:
<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>
Este código debería iniciar la actividad:
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);
}
});
en el onResume de DashboardActivity verifico la acción correspondiente:
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);
}
Pero cuando ejecuto este código, siempre obtengo el android.intent.action.MAIN
acción.Si elimino el singleTop
modo de inicio, inicia una nueva actividad, pero pasa la intención correcta.Tengo que usar la misma instancia de la actividad, entonces singleTop
, singleTask
o singleInstance
debe hacer el trabajo.Pero no sé qué está pasando aquí.¡AYUDA!
Solución
Intent.ACTION_VIEW.equals(intent.getAction())
¿De dónde viene esta intención?Para captar el nuevo Intent debes usarenNuevaIntención().
Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow