欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

Android  隱式Intent的實(shí)例詳解

 更新時(shí)間:2017年08月04日 14:34:22   作者:System_err  
這篇文章主要介紹了Android 隱式Intent的實(shí)例詳解的相關(guān)資料,隱式意圖就是在不明確設(shè)置激活對(duì)象的前提下尋找最匹配的組件,需要的朋友可以參考下

Android  隱式Intent的實(shí)例詳解

前言:

顧名思義,隱式意圖就是在不明確設(shè)置激活對(duì)象的前提下尋找最匹配的組件,舉個(gè)例子,比如有5個(gè)人:

(1)A:170cm
(2)B:160cm
(3)C:180cm
(4)D:190cm
(5)E:200cm

如果是顯示意圖的話,如果我們要指明選擇A的話會(huì)說:”我選擇A.“,但是如果是隱式意圖,則會(huì)說:”我要選擇170cm的人“,雖然沒有指明要選A,但會(huì)尋找條件最匹配的人。

在intent過濾器中類似于上面例子中的”身高“條件的匹配條件有:

(1)action
(2)category
(3)data:scheme、host、path、type

當(dāng)在程序中設(shè)置了這些激活組件的條件,程序就會(huì)去尋找最匹配的組件,但是注意:只要有一點(diǎn)不匹配,則就是不匹配;

比如:

Intent intent = new Intent();
intent.setAction("a");//此句只是指定了Action
startActivity(intent);//尋找最匹配的組件激活,內(nèi)部會(huì)調(diào)用intent.addCategory("Android.intent.category.DEFAULT"); 

隱式Intent的核心代碼

首先是在AndroidManifest.xml中為某個(gè)Activity設(shè)置意圖過濾器:

<activity> 
  <intent-filter> 
    <action android:name="...."/> 
    <category android:name="...."/> 
    <category android:name="android.intent.category.DEFAULT"/>  <!--此句一般都要加 --> 
    <data android:scheme="..." android:host="..." android:path="/..." android:type="..."/> 
  </intent-filter> 
</activity> 

以上設(shè)置是設(shè)置Activity本身的屬性,接下來在程序中要設(shè)置的是我們要尋找時(shí)匹配的條件:

(1)Intent intent = new Intent();
(2)intent.setAction("....");
(3)intent.addCategory("....");
(4)intent.setData(Uri.parse("...."));//設(shè)置data的scheme、host、path條件
(5)intent.setDataAndType(Uri.parse(""),String type);//同時(shí)設(shè)置data的scheme、host、path、type條件
(6)startActivity(intent);//調(diào)用intent.addCategory("android.intent.category.DEFAULT");

以上就是Android 隱式Intent 的詳解,如有疑問請(qǐng)留言或者到本站社區(qū)交流討論,感謝閱讀,希望能幫到大家,謝謝大家對(duì)本站的支持!

相關(guān)文章

最新評(píng)論