android.intent.category.DEFAULT

來源:互聯網
上載者:User

標籤:

我們需要什麼時候加android.intent.category.DEFAULT呢?

1、要弄清楚這個問題,首先需要弄明白什麼是implicit(隱式) intent什麼是explicit(顯示) intent。

     Explicit Intent明確的指定了要啟動的Acitivity ,比如以下Java代碼: 
             Intent intent= new Intent(this, B.class)

     Implicit Intent沒有明確的指定要啟動哪個Activity ,而是通過設定一些Intent Filter來讓系統去篩選合適的Acitivity去啟動。

2、intent到底發給哪個activity,需要進行三個匹配,一個是action,一個是category,一個是data。

理論上來說,如果intent不指定category,那麼無論intent filter的內容是什麼都應該是匹配的。但是,如果是implicit intent,android預設給加上一個CATEGORY_DEFAULT,這樣的話如果intent filter中沒有android.intent.category.DEFAULT這個category的話,匹配測試就會失敗。所以,如果你的 activity支援接收implicit intent的話就一定要在intent filter中加入android.intent.category.DEFAULT。

例外情況是:android.intent.category.MAIN和android.intent.category.LAUNCHER的filter中沒有必要加入android.intent.category.DEFAULT,當然加入也沒有問題。

我們定義的activity如果接受implicit intent的話,intent filer就一定要加上android.intent.category.DEFAULT這個category。

      我的問題就是出現在這裡。忘記在intent-filter中加上了<category android:name="android.intent.category.DEFAULT" />了這個。

 

轉自:http://www.cnblogs.com/roemin/archive/2011/08/11/2134442.html

android.intent.category.DEFAULT

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.