【正文】
ndroid系統(tǒng)則通過匹配動(dòng)作和數(shù)據(jù)格式,找到最適合于此動(dòng)作和數(shù)據(jù)格式的組件。 startActivity(intent)。 ? Keyvalue pairs that carry additional information required to acplish the requested action. ? 一些 actions與特殊的 extras相配 。 ? 資源 ? 標(biāo)識(shí)形式多樣: URL, URN URI={URL, URN, ……} ? URI語法成分 scheme:schemespecificpart scheme :Just as there are many different methods of access to resources, there are a variety of schemes for identifying such resources. It defines the semantics for the remainder of the URI string. Android中的 URI ? Each part of the URI: ? For example, ? the scheme is content, the host is , the port is 200, and the path is folder/subfolder/etc. The host and port together constitute the URI authority。在運(yùn)行時(shí)綁定在同一應(yīng)用或不同應(yīng)用的組件。 如果設(shè)置, intent對象就發(fā)送給該類的實(shí)例; 如果沒設(shè)置, Android會(huì)使用 intent對象的其它信息去定位一個(gè)適合的目標(biāo)。在一個(gè) intent對象中 可以放置任意多個(gè)類型描述 。 Intent的用途 ?啟動(dòng) Activity和 Service ?在 Android系統(tǒng)上發(fā)布廣播消息 — 可以是接收到的特定數(shù)據(jù)或消息,也可以是手機(jī)的信號(hào)變化或電池的電量低等信息 給每種組件發(fā)送 intent都有不同的機(jī)制 啟動(dòng) Activity ? 在 Android系統(tǒng)中,應(yīng)用程序一般都有多個(gè)Activity, Intent可以 實(shí)現(xiàn)不同 Activity之間的切換和數(shù)據(jù)傳遞 – 啟動(dòng) Activity方式 ? 顯式啟動(dòng) :必須在 Intent中指明啟動(dòng)的 Activity ? 隱式啟動(dòng) : Intent無需指明具體啟動(dòng)哪一個(gè) Activity, Android系統(tǒng)根據(jù) Intent的 action、 data和category來決定啟動(dòng)哪一個(gè) Activity。 ? Android系統(tǒng)會(huì)在程序運(yùn)行時(shí)解析 Intent,并根據(jù)一定的規(guī)則對 Intent中的 action、 data和 category與 Activity的 intent過濾器 中的匹配。 2. Intent intent = new Intent(, )。 在子 Activity中設(shè)置返回值 ?以下代碼說明如何在子 Activity中設(shè)置返回值 : 1. Uri data = (tel: + tel_number)。根據(jù)返回?cái)?shù)據(jù)的用途不同,Uri數(shù)據(jù)的協(xié)議也不同,也可以使用 Extra方法直接返回?cái)?shù)據(jù)本身。 ”關(guān)閉“:返回“ RESULT_CANCLED”狀態(tài)給 MainActivity。 ? 一個(gè)組件可以有多個(gè) intent過濾器,沒有匹配其中一個(gè),卻可能匹配另一個(gè)。通過 data部分匹配測試。 ? 這樣, Android系統(tǒng)便可以將任何一個(gè) Intent請求通過 Intent過濾器映射到相應(yīng)的組件上。 ( 3) 接收的 BroadcastReceiver: 繼承BroadcastReceiver類 ,重寫 onReceive()方法。 ? 編程實(shí)現(xiàn)具有“登錄”按鈕的主界面,點(diǎn)擊“登錄”按鈕后打開一個(gè)新的 Activity,新打開的 Activity上面有輸入用戶名和密碼的控件,在用戶關(guān)閉這個(gè)Activity后,將用戶名和密碼傳遞到主界面的 Activity中。 ? 要在 Intent傳遞附加信息,用 Intent的 putExtra()方法。 ? 廣播消息的內(nèi)容 :與應(yīng)用程序密切相關(guān)的數(shù)據(jù)信息,Android的系統(tǒng)信息,如網(wǎng)絡(luò)連接變化、電池電量低、接收到短信或系統(tǒng)設(shè)置變化等。如:不引用實(shí)際數(shù)據(jù)的 mailto:和 tel:。 Intent與 Intent過濾器的匹配策略 ? category test 情況 1: intent對象可有多個(gè) category,每一個(gè)