Domanda

Sto lottando con il seguente strano comportamento delle attività singletop.

Ho definito alcuni filtri intenzionali in quell'attività:

<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>
.

Questo codice dovrebbe avviare l'attività:

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);    

        }

    });
.

In Onresume del DashboardActivity Controllo per il secondo azione:

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);
}
.

Ma quando eseguo questo codice, ottengo sempre l'azione android.intent.action.MAIN.Se rimuovo la modalità di lancio singleTop, avvia una nuova attività, ma passa l'intento corretto.Devo usare la stessa istanza dell'attività, quindi singleTop, singleTask o singleInstance deve fare il lavoro.Ma non so cosa stia sbagliando qui.Aiuto!

È stato utile?

Soluzione

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

Da dove viene questo intento?Per prendere il nuovo intento devi usare onnewintent () . .

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top