一.綜述
成都創(chuàng)新互聯(lián)公司是專業(yè)的霍城網(wǎng)站建設(shè)公司,霍城接單;提供網(wǎng)站制作、成都網(wǎng)站建設(shè),網(wǎng)頁設(shè)計(jì),網(wǎng)站設(shè)計(jì),建網(wǎng)站,PHP網(wǎng)站建設(shè)等專業(yè)做網(wǎng)站服務(wù);采用PHP框架,可快速的進(jìn)行霍城網(wǎng)站開發(fā)網(wǎng)頁制作和功能擴(kuò)展;專業(yè)做搜索引擎喜愛的網(wǎng)站,專業(yè)的做網(wǎng)站團(tuán)隊(duì),希望更多企業(yè)前來合作!
intent對象是一個信息桶。它包含了接收它的組件感興趣的信息(如:攜帶的動作和數(shù)據(jù)),附加Android系統(tǒng)感興趣的信息(如:處理intent和啟動目標(biāo)Activity指令的組件的類別)
程序的3個核心組件——Activity、services、廣播接收器——是通過intent傳遞消息的。intent消息對于運(yùn)行時綁定不同的組件是很方便的,這些組件可以是同一個程序也可以是不同的。一個intent對象,是一個被動的數(shù)據(jù)結(jié)構(gòu),它保存了一個操作的抽象描述——或通常是一個廣播的實(shí)例,一些發(fā)生的事情的描述,一個通知。傳遞intent到不同組件的機(jī)制是互不相同的。
intent對象是傳遞給Context.startActivity() 或Activity.startActivityForResult() 以啟動Activity或是讓一個存在的Activity做些事情。(也可以傳遞給Activity.setResult()來返回Activity的信息,這個函數(shù)叫startActivityForResult()。)
intent對象傳遞給函數(shù)來初始化一個service或是分發(fā)一個新的指令給一個正在進(jìn)行的service。同樣,intent傳遞給來建立一個在調(diào)用組件和目標(biāo)service間的聯(lián)系。如果一個service沒有運(yùn)行,它可以開始它。
intent可以傳遞給任何廣播函數(shù)(如:Context.sendBroadcast()、Context.sendOrderedBroadcast()、 Context.sendStickyBroadcast()),intent被分派給所有感興趣的廣播接收者。很多廣播源在系統(tǒng)內(nèi)核里。
Android系統(tǒng)會尋找合適的Activity、service或設(shè)置廣播接收器來響應(yīng)intent,在需要的時候?qū)嵗鼈儭T谙⑾到y(tǒng)里沒有交疊:廣播intent僅僅分派給廣播接收器,不會分派給Activity或service。一個intent分派給startActivity()僅僅分派給Activity,不會分派給service或廣播接收器,等等。
二.Intent關(guān)聯(lián)的東西

@1四大組件Activity,Brocast,Service,Receiver,intent可以在四大組件中傳遞消息和數(shù)據(jù)。
@2動作Action,通過 setAction()函數(shù)設(shè)置,通過getAction()函數(shù)讀取
@3數(shù)據(jù)Data,數(shù)據(jù)的URI和MIME類型的數(shù)據(jù),setData() 函數(shù)指定數(shù)據(jù)作為一個URI, setType()指定它為一個MIME類型,setDataAndType()指定它是URI也是MIME類型。 getData()函數(shù)讀取URI, getType()讀取類型
@4類型addCategory() 放置一個intent里的類別,removeCategory()刪除之前添加的,getCategories()獲取當(dāng)前所有的類別。
@5擴(kuò)展,intent有一系列的put...() 函數(shù)來插入各種類型的數(shù)據(jù)和一系列g(shù)et...()函數(shù)來獲取各種類型的數(shù)據(jù)。對Bundle 對象,這些函數(shù)是并行的。事實(shí)上,可以使用函數(shù)putExtras()和函數(shù)getExtras()來把數(shù)據(jù)作為Bundle讀取、插入
@6標(biāo)志,各種排序的標(biāo)志。指示Android如何啟動Activity(例如:Activity屬于那個任務(wù))啟動后如何處理(例如:是否屬于現(xiàn)在Activity 的列表)。這些標(biāo)志在intent類里定義。
和平臺相關(guān)的Android系統(tǒng)和程序使用intent來發(fā)送系統(tǒng)的廣播、激活系統(tǒng)定義的組件。和intent激活系統(tǒng)組件相關(guān)的內(nèi)容,在list of intents
三.Intent的分類
1.顯示意圖Intent


/**
* 顯示意圖開啟activity
*
* @param view */
public void see(View view) {
Intent intent = new Intent(this,MyActivity.class);
startActivity(intent);
}
2.隱式意圖Intent

實(shí)例程序:
@1開啟本應(yīng)用的Activity

= Intent("com.market.textintent.MY""huihui:"+123456),"pp/my"

<?xml version="1.0" encoding="utf-8"?><manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.market.testintent"> <uses-permission android:name="android.permission.SEND_SMS" /> <application android:allowBackup="true" android:icon="@mipmap/ic_launcher" android:label="@string/app_name" android:supportsRtl="true" android:theme="@style/AppTheme"> <activity android:name="market.testintent.MainActivity"> <intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> </intent-filter> </activity> <activity android:name="market.testintent.MyActivity"> <intent-filter> <action android:name="com.market.textintent.MY"/> <category android:name="android.intent.category.DEFAULT"/> <data android:scheme="huihui"/> <data android:mimeType="pp/my"/> </intent-filter> </activity> </application></manifest>


<?xml version="1.0" encoding="utf-8"?><LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:layout_width="match_parent" android:gravity="center_horizontal" android:padding="20dp" android:layout_height="match_parent"> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginTop="20dp" android:text="測試Intent" /> <Button android:onClick="send" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="發(fā)短信" /> <Button android:onClick="start" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="startMyActivity" /> <Button android:onClick="see" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="顯示意圖" /></LinearLayout>


@2開啟系統(tǒng)應(yīng)用Activity

/**
* y隱式意圖發(fā)短信
*
* @param view */
public void send(View view) {
Intent intent = new Intent();
intent.setAction(Intent.ACTION_VIEW );
intent.addCategory(Intent.CATEGORY_DEFAULT);
intent.setType("vnd.android-dir/mms-sms");
intent.putExtra("sms_body","美女,你吃飯了沒?");
startActivity(intent);
}
短信應(yīng)用清單文件activity配置


本文名稱:Intent解析
分享鏈接:http://chinadenli.net/article30/jiggpo.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供響應(yīng)式網(wǎng)站、網(wǎng)站內(nèi)鏈、網(wǎng)站收錄、品牌網(wǎng)站設(shè)計(jì)、服務(wù)器托管、企業(yè)網(wǎng)站制作
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請盡快告知,我們將會在第一時間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時需注明來源: 創(chuàng)新互聯(lián)