2014-04-11 19 views
1

我正在努力處理SingleTop活動的下列奇怪行爲。Android: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);  

     } 

    }); 
在DashboardActivity的的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啓動模式,它將啓動一個新的活動,但傳遞正確的意圖。我必須使用相同的活動實例,所以singleTop,singleTasksingleInstance必須完成這項工作。但我不知道這裏出了什麼問題。幫幫我!

回答

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

這個意圖來自哪裏?爲了趕上新的意圖,你必須使用 onNewIntent()