Pergunta

Eu estou lutando com o seguinte comportamento estranho de SingleTop atividades.

Eu tenho definido alguns intenção de filtros em que atividade:

<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 deve iniciar a atividade:

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

        }

    });

no onResume do DashboardActivity eu seleção para o de acordo com a ação:

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

Mas quando eu executar esse código, eu sempre fico com o android.intent.action.MAIN a ação.Se eu remover o singleTop modo de lançamento, inicia uma nova atividade, mas passa a correta intenção.Eu tenho que usar a mesma instância de atividade, por singleTop, singleTask ou singleInstance tem de fazer o trabalho.Mas eu não sei o que está acontecendo de errado aqui.AJUDA!

Foi útil?

Solução

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

Onde é que esta a intenção de vir?A fim de pegar o new Intent, você deve usar onNewIntent().

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top