當前位置:首頁 » 安卓系統 » android的intent

android的intent

發布時間: 2023-07-26 01:44:54

① android中intent的作用 越詳細越好

1 Intent.ACTION_MAIN

String: android.intent.action.MAIN

標識Activity為一個程序的開始。比較常用。

Input:nothing

Output:nothing

例如:

1
2
3
4
5
6

也可以直接在程序中實現 Intent it = new Intent(原Activity.class,需跳轉Activity.class);
2 Intent.Action_CALL

Stirng: android.intent.action.CALL

呼叫指定的電話號碼。

Input:電話號碼。數據格式為:tel:+phone number

Output:Nothing

Intent intent=new Intent();
intent.setAction(Intent.ACTION_CALL);
intent.setData(Uri.parse("tel:1320010001");
startActivity(intent);

3 Intent.Action.DIAL

String: action.intent.action.DIAL

調用撥號面板

Intent intent=new Intent();
intent.setAction(Intent.ACTION_DIAL); //android.intent.action.DIAL
intent.setData(Uri.parse("tel:1320010001");
startActivity(intent);

Input:電話號碼。數據格式為:tel:+phone number

Output:Nothing

說明:打開Android的撥號UI。如果沒有設置數據,則打開一個空的UI,如果設置數據,action.DIAL則通過調用getData()獲取電話號碼。

但設置電話號碼的數據格式為 tel:+phone number.

4.Intent.Action.ALL_APPS

String: andriod.intent.action.ALL_APPS

列出所有的應用。

Input:Nothing.

Output:Nothing.

5.Intent.ACTION_ANSWER

Stirng:android.intent.action.ANSWER

處理呼入的電話。

Input:Nothing.

Output:Nothing.

6 Intent.ACTION_ATTACH_DATA

String: android.action.ATTCH_DATA

別用於指定一些數據應該附屬於一些其他的地方,例如,圖片數據應該附屬於聯系人

Input: Data

Output:nothing

7 Intent.ACTION_BUG_REPORT

String: android.intent.action.BUG_REPORT

顯示Dug報告。

Input:nothing

output:nothing

8 Intent.Action_CALL_BUTTON

String: android.action.intent.CALL_BUTTON.

相當於用戶按下「撥號」鍵。經測試顯示的是「通話記錄」

Input:nothing

Output:nothing

Intent intent = new Intent(Intent.ACTION_CALL_BUTTON);
startActivity(intent);

9 Intent.ACTION_CHOOSER

String: android.intent.action.CHOOSER

顯示一個activity選擇器,允許用戶在進程之前選擇他們想要的,與之對應的是Intent.ACTION_GET_CONTENT.

10. Intent.ACTION_GET_CONTENT

String: android.intent.action.GET_CONTENT

允許用戶選擇特殊種類的數據,並返回(特殊種類的數據:照一張相片或錄一段音)

Input: Type

Output:URI

這個以前用到過,看事例。

選擇一個圖片:

代碼
int requestCode = 1001;

Intent intent = new Intent(Intent.ACTION_GET_CONTENT); // "android.intent.action.GET_CONTENT"
intent.setType("image/*"); // 查看類型,如果是其他類型,比如視頻則替換成 video/*,或 */*
Intent wrapperIntent = Intent.createChooser(intent, null);
startActivityForResult(wrapperIntent, requestCode);

② 大學期末復習 android 中 intent組件的屬性有哪些

Intent主要有以下四個重要屬性,它們分別為:
Action:Action屬性的值為一個字元串,它代表了系統中已經定義了一系列常用的動作。通過setAction()方法或在清單文件AndroidManifest.xml中設置。默認為:DEFAULT。
Data:Data通常是URI格式定義的操作數據。例如:tel:// 。通過setData()方法設置。
Category:Category屬性用於指定當前動作(Action)被執行的環境。通過addCategory()方法或在清單文件AndroidManifest.xml中設置。默認為:CATEGORY_DEFAULT。
Extras:Extras屬性主要用於傳遞目標組件所需要的額外的數據。通過putExtras()方法設置。
四個屬性各自的常用值如下所示:
Action:
ACTION_MAIN:Android Application的入口,每個Android應用必須且只能包含一個此類型的Action聲明。
ACTION_VIEW:系統根據不同的Data類型,通過已注冊的對應Application顯示數據。
ACTI ON_EDIT:系統根據不同的Data類型,通過已注冊的對應Application編輯示數據。
ACTION_DIAL:打開系統默認的撥號程序,如果Data中設置了電話號碼,則自動在撥號程序中輸入此號碼。
ACTION_CALL:直接呼叫Data中所帶的號碼。
ACTION_ANSWER:接聽來電。
ACTION_SEND:由用戶指定發送方式進行數據發送操作。
ACTION_SENDTO:系統根據不同的Data類型,通過已注冊的對應Application進行數據發送操作。
ACTION_BOOT_COMPLETED:Android系統在啟動完畢後發出帶有此Action的廣播(Broadcast)。
ACTION_TIME_CHANGED:Android系統的時間發生改變後發出帶有此Action的廣播(Broadcast)。
ACTION_PACKAGE_ADDED:Android系統安裝了新的Application之後發出帶有此Action的廣播(Broadcast)。
ACTION_PACKAGE_CHANGED:Android系統中已存在的Application發生改變之後(如應用更新操作)發出帶有此Action的廣播(Broadcast)。
ACTION_PACKAGE_REMOVED:卸載了Android系統已存在的Application之後發出帶有此Action的廣播(Broadcast)。
Category:
CATEGORY_DEFAULT:Android系統中默認的執行方式,按照普通Activity的執行方式執行。
CATEGORY_HOME:設置該組件為Home Activity。
CATEGORY_PREFERENCE:設置該組件為Preference。
CATEGORY_LAUNCHER:設置該組件為在當前應用程序啟動器中優先順序最高的Activity,通常為入口ACTION_MAIN配合使用。
CATEGORY_BROWSABLE:設置該組件可以使用瀏覽器啟動。
CATEGORY_GADGET:設置該組件可以內嵌到另外的Activity中。
Extras:
EXTRA_BCC:存放郵件密送人地址的字元串數組。
EXTRA_CC:存放郵件抄送人地址的字元串數組。
EXTRA_EMAIL:存放郵件地址的字元串數組。
EXTRA_SUBJECT:存放郵件主題字元串。
EXTRA_TEXT:存放郵件內容。
EXTRA_KEY_EVENT:以KeyEvent對象方式存放觸發Intent的按鍵。
EXTRA_PHONE_NUMBER:存放調用ACTION_CALL時的電話號碼。
Data:
tel://:號碼數據格式,後跟電話號碼。
mailto://:郵件數據格式,後跟郵件收件人地址。
smsto://:短息數據格式,後跟簡訊接收號碼。
content://:內容數據格式,後跟需要讀取的內容。
file://:文件數據格式,後跟文件路徑。
market://search?q=pname:pkgname:市場數據格式,在Google Market里搜索包名為pkgname的應用。
geo://latitude, longitude:經緯數據格式,在地圖上顯示經緯度所指定的位置。

③ android當中顯式intent和隱式intent的區別

區別如下:

  1. 顯式啟動Activity指的是在Intent內部直接聲明要啟動的activity所對應的class。

  2. 隱式啟動Activity的intent到底發給哪個activity,需要進行三個匹配,一個是action, 一個是category,一個是data,可以是全部或部分匹配,同樣適用於Service和BroadcastReceiver。

A:顯式啟動
下面用代碼來解釋什麼是顯式啟動。
Intent intent=new Intent(MainActivity.this, SecondActivity.class);
startActivity(intent);
B:隱式啟動
隱式啟動不同之處在於並不需要像Intent(MainActivity.this, SecondActivity.class)這樣傳參數然後再Start另一個Activity.需要在intent添加過濾器intentfilter。
<activity
android:name="com.example.android.tst.SecondActivity"
android:label="@string/title_activity_main" >
<intent-filter>
<action android:name="com.example.android.tst.SecondActivity"/>
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
這樣,需要在啟動另一個Activity的時候只需要如下方法就可以:
Intent intent=new Intent("com.example.android.tst.SecondActivity");
startActivity(intent);

④ android中intent什麼意思

英文里 Intent是「意向、打算」的意思,其實就是告訴別人你的意圖的意思了,這么理解Android裡面的Intent也就不難了。

書面化的解釋是:
Android中提供了Intent機制來協助應用間的交互與通訊,Intent負責對應用中一次操作的動作、動作涉及數據、附加數據進行描述,Android則根據此Intent的描述,負責找到對應的組件,將 Intent傳遞給調用的組件,並完成組件的調用。Intent不僅可用於應用程序之間,也可用於應用程序內部的Activity/Service之間的交互。因此,Intent在這里起著一個媒體中介的作用,專門提供組件互相調用的相關信息,實現調用者與被調用者之間的解耦。

⑤ android開發intent怎麼傳遞集合

1、Intent(意圖)主要是解決Android應用的各項組件之間的通訊。
2、為了實現傳遞數據這個目的需要以下步驟
3、Activity1需要構造一個 Intent,這個Intent用於告訴系統,我們要做「查看」動作
intent可調用putExtra來存放想要傳遞的數據
4、然後調用setClass,設置Activity1和欲調用的組件Activity2
5、最後調用startActivity將構造的Intent傳入,系統會根據此Intent中的描述,到Activity1中找到滿足此Intent要求的Activity,系統會調用找到的 Activity2最終傳入Intent在Activity2中可使用getIntent來獲取傳遞的Intent,並通過獲取數據的方法來獲取數據代碼示例:
Intent intent = new Intent(); // Activity1
intent.putExtra("one", num1);
intent.putExtra("two", num2);
intent.setClass(FirstActivity.this, SecondActivity.class);
startActivity(intent); Intent intent = getIntent(); //Activity2
String num1 = intent.getStringExtra("one");
String num2 = intent.getStringExtra("two");
int ret = Integer.parseInt(num1) + Integer.parseInt(num2);
result.setText(ret+"");
注意:在使用intent的時候可以使用bundle傳遞復制的數據類型。

⑥ Android開發之Intent.Action Android中Intent的各種常見作用【轉】

1 Intent.ACTION_MAIN

String: Android.intent.action.MAIN標識Activity為一個程序的開始。比較常用。Input:nothingOutput:nothing

2 Intent.Action_CALL

【直接呼叫,在6.0之後的版本需要獲取許可權,詳見 Android開發學習之路-Android6.0運行時許可權【轉】 】

Stirng: android.intent.action.CALL呼叫指定的電話號碼。Input:電話號碼。數據格式為:tel:+phone number Output:Nothing

Intent intent=new Intent(); intent.setAction(Intent.ACTION_CALL);

intent.setData(Uri.parse("tel:1320010001");

startActivity(intent);

3 Intent.Action.DIAL

String: action.intent.action.DIAL調用撥號面板

Intent intent=new Intent();intent.setAction(Intent.ACTION_DIAL);  //android.intent.action.DIAL

intent.setData(Uri.parse("tel:1320010001");

startActivity(intent);

Input:電話號碼。數據格式為:tel:+phone number Output:Nothing說明:打開Android的撥號UI。如果沒有設置數據,則打開一個空的UI,如果設置數據,action.DIAL則通過調用getData()獲取電話號碼。但設置電話號碼的數據格式為 tel:+phone number.

4 Intent.Action.ALL_APPS

String: andriod.intent.action.ALL_APPS列出所有的應用。Input:Nothing.Output:Nothing.

5Intent.ACTION_ANSWER

Stirng:android.intent.action.ANSWER處理呼入的電話。Input:Nothing.Output:Nothing.

6 Intent.ACTION_ATTACH_DATA

String: android.action.ATTCH_DATA別用於指定一些數據應該附屬於一些其他的地方,例如,圖片數據應該附屬於聯系人Input: DataOutput:nothing

7 Intent.ACTION_BUG_REPORT

String: android.intent.action.BUG_REPORT顯示Dug報告。Input:nothingoutput:nothing

8 Intent.Action_CALL_BUTTON

String: android.action.intent.CALL_BUTTON.相當於用戶按下「撥號」鍵。經測試顯示的是「通話記錄」Input:nothingOutput:nothing

Intent intent = new Intent(Intent.ACTION_CALL_BUTTON);startActivity(intent);

9 Intent.ACTION_CHOOSER

String: android.intent.action.CHOOSER顯示一個activity選擇器,允許用戶在進程之前選擇他們想要的,與之對應的是Intent.ACTION_GET_CONTENT.

10. Intent.ACTION_GET_CONTENT

String: android.intent.action.GET_CONTENT允許用戶選擇特殊種類的數據,並返回(特殊種類的數據:照一張相片或錄一段音)

Input: TypeOutput:URI

int requestCode = 1001;Intent intent = new Intent(Intent.ACTION_GET_CONTENT); // "android.intent.action.GET_CONTENT"

intent.setType("image/*"); // 查看類型,如果是其他類型,比如視頻則替換成 video/*,或 */*

Intent wrapperIntent = Intent.createChooser(intent, null);startActivityForResult(wrapperIntent, requestCode);

11 Intent.ACTION_VIEW

String:android.intent.action.VIEW用於顯示用戶的數據。比較通用,會根據用戶的數據類型打開相應的Activity。比如 tel:13400010001打開撥號程序,http://www.g.cn則會打開瀏覽器等。

Uri uri = Uri.parse("http://www.google.com"); //瀏覽器 Uri uri =Uri.parse("tel:1232333"); //撥號程序

Uri uri=Uri.parse("geo:39.899533,116.036476"); //打開地圖定位

Intent it = new Intent(Intent.ACTION_VIEW,uri);

startActivity(it);

//播放視頻

Intent intent = new Intent(Intent.ACTION_VIEW);

Uri uri = Uri.parse("file:///sdcard/media.mp4");

intent.setDataAndType(uri, "video/*");

startActivity(intent);

//調用發送簡訊的程序

Intent it = new Intent(Intent.ACTION_VIEW);

it.putExtra("sms_body", "信息內容...");

it.setType("vnd.android-dirs-sms");

startActivity(it);

12 Intent.ACTION_SENDTO

String: android.intent.action.SENDTO

說明:發送簡訊息

//發送簡訊息 Uri uri = Uri.parse("smsto:13200100001");

Intent it = new Intent(Intent.ACTION_SENDTO, uri);

it.putExtra("sms_body", "信息內容...");

startActivity(it);

//發送彩信,設備會提示選擇合適的程序發送 Uri uri = Uri.parse("content://media/external/images/media/23");

//設備中的資源(圖像或其他資源)

Intent intent = new Intent(Intent.ACTION_SEND);

intent.putExtra("sms_body", "內容");

intent.putExtra(Intent.EXTRA_STREAM, uri);

intent.setType("image/png");

startActivity(it);

//Email Intent intent=new Intent(Intent.ACTION_SEND);

String[] tos={"[email protected]"};

String[] ccs={"[email protected]"};

intent.putExtra(Intent.EXTRA_EMAIL, tos);

intent.putExtra(Intent.EXTRA_CC, ccs);

intent.putExtra(Intent.EXTRA_TEXT, "The email body text");

intent.putExtra(Intent.EXTRA_SUBJECT, "The email subject text");

intent.setType("message/rfc822");

startActivity(Intent.createChooser(intent, "Choose Email Client"));

13 Intent.ACTION_GET_CONTENT

//選擇圖片 requestCode 返回的標識

Intent intent = new Intent(Intent.ACTION_GET_CONTENT); //"android.intent.action.GET_CONTENT"

intent.setType(contentType); //查看類型 String IMAGE_UNSPECIFIED = "image/*";

Intent wrapperIntent = Intent.createChooser(intent, null);

((Activity) context).startActivityForResult(wrapperIntent, requestCode);

//添加音頻

Intent intent = new Intent(Intent.ACTION_GET_CONTENT);

intent.setType(contentType); //String VIDEO_UNSPECIFIED = "video/*";

Intent wrapperIntent = Intent.createChooser(intent, null);

((Activity) context).startActivityForResult(wrapperIntent, requestCode);

//拍攝視頻

int rationLimit = getVideoCaptureDurationLimit(); //SystemProperties.getInt("ro.media.enc.lprof.ration", 60);

Intent intent = new Intent(MediaStore.ACTION_VIDEO_CAPTURE);

intent.putExtra(MediaStore.EXTRA_VIDEO_QUALITY, 0);

intent.putExtra(MediaStore.EXTRA_SIZE_LIMIT, sizeLimit);

intent.putExtra(MediaStore.EXTRA_DURATION_LIMIT, rationLimit);

startActivityForResult(intent, REQUEST_CODE_TAKE_VIDEO);

//視頻

Intent intent = new Intent(Intent.ACTION_GET_CONTENT);

intent.setType(contentType); //String VIDEO_UNSPECIFIED = "video/*";

Intent wrapperIntent = Intent.createChooser(intent, null);

((Activity) context).startActivityForResult(wrapperIntent, requestCode);

//錄音

Intent intent = new Intent(Intent.ACTION_GET_CONTENT);

intent.setType(ContentType.AUDIO_AMR); //String AUDIO_AMR = "audior";

intent.setClassName("com.android.soundrecorder",

"com.android.soundrecorder.SoundRecorder");

((Activity) context).startActivityForResult(intent, requestCode);

//拍照 REQUEST_CODE_TAKE_PICTURE 為返回的標識

Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE); //"android.media.action.IMAGE_CAPTURE";

intent.putExtra(MediaStore.EXTRA_OUTPUT, Mms.ScrapSpace.CONTENT_URI); // output,Uri.parse("content:/s/scrapSpace");

startActivityForResult(intent, REQUEST_CODE_TAKE_PICTURE);

⑦ android中為什麼要使用intent進行通信

1、Intent對象詳解
Android的應用程序包含三種重要組件:Activity、Service、BroadcastReceiver,應用程序採用一致的方式來啟動它們----都是依靠Intent來進行啟動的,Intent就封裝了程序想要啟動程序的意圖,不僅如此,Intent還用於與被啟動組件進行交換信息。

組件類型

啟動方法

Activity
startActivity(Intent intent)
startActivityForResult(Intent intent,intrequestCode)

Service
ComponentName startService(Intent service)
boolean bindService(Intent service,ServiceConnection conn,int flags)

BroadcastReceiver
sendBroadcast(Intent intent)
sendBroadcast(Intent intent,String receiverPermission)
sendOrderedBroadcast(Intent intent,String receiverPermission,BroadcastReceiver resultReceiver,Handler scheler,int initialCode,String initialData,Bundle initialExtras)
sendOrderedBroadcast(Intent intent,String receiverPermission)
sendStickyOrderedBroadcast(Intent intent,BroadcastReceiver resultReceiver,Handler scheler,int initialCode,String initialData,Bundle initialExtras)

Intent對象大致包含Component、Action、Category、Data、Type、Extra和Flag這7種屬性,其中Component用於明確指定需要啟動的目標組件,而Extra則用於「攜帶」需要交換的數據。
2、Intent的屬性及Intent-filter配置
(1)Component屬性
Intent的Component屬性需要接受一個ComponentName對象,應用程序可根據給定的組件類去啟動特定的組件。
當程序通過Intent的Component屬性(明確指定了啟動哪個組件)啟動特定組件時,被啟動組件幾乎不需要使用<intent-filter.../>元素進行配置。
(2)Action、Category屬性與intent-filter配置
Intent的Action和Category屬性都是一個普通的字元串,其中Action代表該Intent所要完成的一個抽象「動作」,Category則用於為Action增加額外的附加類別信息,通常,Action與Category結合使用。
<intent-filter.../>元素里通常可包括如下子元素:
a、0~N個<action.../>子元素
b、0~N個<category.../>子元素
c、0~1個<data.../>子元素
<action.../><category.../>子元素的配置非常簡單,它們都可指定android:name屬性,該屬性的值就是一個普通字元串。
當<activity.../>元素里的<intent-filter.../>子元素里包含多個<action.../>子元素(相當於指定了多個字元串)時,就表明該Activity能響應Action屬性值為其中任意一個字元串的Intent。
一個Intent對象最多隻能包括一個Action屬性,程序調用Intent的setAction(String str)方法來設置Action屬性值;但一個Intent對象可包含多個Category屬性,調用Intent的addCategory(String str)方法添加。
當程序創建Intent時,該Intent默認啟動Category屬性值為Intent.CATEGORY_DEFAULT常量(常量值為android.intent.category.DEFAULT)的組件。
(3)指定Action、Category調用系統Activity
實際上,Android內部提供了大量標准Action、Category常量,其中用於啟動Activity的標准Action常量及對應的字元串如下:

Action常量

對應字元串

簡單說明

ACTION_MAIN

android.intent.action.MAIN

應用程序入口

ACTION_VIEW android.intent.action.VIEW 顯示指定數據
ACTION_ATTACH_DATA android.intent.action.ATTACH_DATA 指定某塊數據將被附加到其它地方
ACTION_EDIT android.intent.action.EDIT 編輯指定數據
ACTION_PICK android.intent.action.PICK 從列表中選擇某項並返回所選的數據
ACTION_CHOOSER android.intent.action.CHOOSER 顯示一個Activity選擇器
ACTION_GET_CONTENT android.intent.action.GET_CONTENT 讓用戶選擇數據,並返回所選數據
ACTION_DIAL android.intent.action.DIAL 顯示撥號面板
ACTION_CALL android.intent.action.CALL 直接向指定用戶打電話
ACTION_SEND android.intent.action.SEND 向其他人發送數據
ACTION_SENDTO android.intent.action.SENDTO 向其他人發送消息
ACTION_ANSWER android.intent.action.ANSWER 應答電話
ACTION_INSERT android.intent.action.INSERT 插入數據
ACTION_DELETE android.intent.action.DELETE 刪除數據
ACTION_RUN android.intent.action.RUN 運行維護
ACTION_SYNC android.intent.action.SYNC 執行數據同步
ACTION_PICK_ACTIVITY android.intent.action.PICK_ACTIVITY 用於選擇Activity
ACTION_SEARCH android.intent.action.SEARCH 執行搜索
ACTION_WEB_SEARCH android.intent.action.WEB_SEARCH 執行Web搜索
ACTION_FACTORY_TEST android.intent.action.FACTORY_TEST 工廠測試的入口點

標准Category常量及對應的字元串如下:

Category常量

對應字元串

簡單說明

CATEGORY_DEFAULT android.intent.category.DEFAULT 默認的Category
CATEGORY_BROWSABLE android.intent.category.BROWSABLE 指定該Activity能被瀏覽器安全調用
CATEGORY_TAB android.intent.category.TAB 指定Activity作為TabActivity的Tab頁
CATEGORY_LAUNCHER android.intent.category.LAUNCHER Activity顯示頂級程序列表中
CATEGORY_INFO android.intent.category.INFO 用於提供包信息
CATEGORY_HOME android.intent.category.HOME 設置該Activity隨系統啟動而運行
CATEGORY_PREFERENCE android.intent.category.PREFERENCE 該Activity是參數面板
CATEGORY_TEST android.intent.category.TEST 該Activity是一個測試
CATEGORY_CAR_DOCK android.intent.category.CAR_DOCK 指定手機被插入汽車底座(硬體)時運行該Activity
CATEGORY_DESK_DOCK android.intent.category.DESK_DOCK 指定手機被插入桌面底座(硬體)時運行該Activity
CATEGORY_CAR_MODE android.intent.category.CAR_MODE 設置該Activity可在車載環境下使用

3、Data、Type屬性與intent-filter配置
Data屬性通常用於向Action屬性提供操作的數據,Data屬性接收一個Uri對象,一個Uri對象通常通過如下形式的字元串表示:
content://com.android.contracts/contacts/1
tel:123
上面兩個字元串的冒號前面大致指定了數據的類型,冒號後面是數據部分。
Type屬性則用於明確指定Data屬性所指定數據的類型或MIME類型,當Intent不指定Data屬性時Type屬性才會起作用,否則Android系統將會根據Data屬性值來分析數據的類型,因此無需指定Type屬性。
一旦為Intent同時指定Action、Data屬性,那麼Android將可根據指定的數據類型來啟動特定的應用程序,並對指定數據執行相應的操作。下面介紹幾個Action、Data屬性的組合:
ACTION_VIEW content://com.android.contacts/contacts/1:顯示標識為1的聯系人的信息
ACTION_EDIT content://com.android.contacts/contacts/1:編輯標識為1的聯系人的信息
ACTION_DIAL content://com.android.contacts/contacts/1:顯示向標識為1的聯系人撥號的界面
ACTION_VIEW tel:123:顯示向指定號碼123撥號的界面
ACTION_DIAL tel:123:顯示向指定號碼123撥號的界面
ACTION_VIEW content://contacts/people/:顯示所有聯系人列表的信息,通過這種組合可以方便地查看系統聯系人
4、Extra屬性
Intent的Extra屬性通常用於在多個Action之間進行數據交換,Intent的Extra屬性值應該是一個Bundle對象,Bundle對象就像一個Map對象,它可以存入多組key-value對,這樣可以就可以通過Intent在不同Activity之間進行數據交換了。

⑧ android中intent的作用

意圖和意圖過濾器Intents and Intent Filters

一個應用程序的三個核心組件-活動,服務和廣播接收器是通過消息即意圖(Intents)來激活的。Intent息傳送是相同或不同應用中組件運行時晚綁定的一種機制。意圖本身,一個意圖對象,是一個包含被執行操作抽象描述的被動的數據結構-或者,對於廣播而言,是某件已經發生並被聲明的事情的描述。存在不同的機制來傳送意圖到每種組件中:
• 一個意圖對象是傳遞給Context.startActivity()或者Activity.startActivityForResult()來啟動一個活動或者讓一個存在的活動去做某些新的事情。
• 一個意圖對象是傳遞給Context.startService()來發起一個服務或者遞交新的指令給運行中的服務。類似的,一個意圖能被傳遞給Context.bindService() 來在調用組件和一個目標服務之間建立連接。作為一個可選項,它可以發起這個服務如果還沒運行的話。
• 傳遞給任意廣播方法(例如Context.sendBroadcast(),Context.sendOrderedBroadcast(), 或者Context.sendStickyBroadcast())的意圖對象被傳遞給所有感興趣的廣播接收者。許多種廣播產生於系統代碼。
在每個例子里,Android系統找到合適的活動,服務,或者一組廣播接收者來回應這個意圖,必要時實例化它們。這些消息傳送系統沒有重疊:廣播意圖僅被傳遞給廣播接收者,永遠不會給活動或者服務。一個傳送給startActivity()的意圖是只會被傳遞給一個活動,永遠不會給一個服務或廣播接收者,如此類推。
這篇文檔以意圖對象的描述開始,然後描述Android映射意圖到組件的規則-如何解決哪個組件應該接收一個意圖消息。對於沒有顯式命名一個目標組件的意圖,這個過程包括對照與潛在目標相關聯的意圖過濾器來測試這個意圖對象。

意圖對象Intent Objects
一個意圖Intent對象是一堆信息。它包含接收這個意圖的組件感興趣的信息(例如將要採取的動作和操作的數據)再加上Android系統感興趣的信息(例如應該處理這個意圖的組件類別和如何啟動一個目標活動的指令):
組件名稱Component name
應該處理這個意圖的組件名字. 這個欄位是一個ComponentName對象- 一個組合物:目標組件的完全合格的類名 (比如"com.example.project.app.FreneticActivity") 以及應用程序描述文件中設置的組件所在包的名字(比如, "com.example.project"). 這個組件名字的包部分和描述文件中設置的包名字不一定要匹配。
組件名字是可選的。如果被設置了,這個意圖對象將被傳遞到指定的類。如果沒有, Android使用另外的意圖對象中的信息去定位一個合適的目標- 請看本文稍後描述的意圖解析Intent Resolution。
組件名字通過如下方法:setComponent(),setClass(), 或者setClassName()設置並通過getComponent()讀取。

熱點內容
c語言中的temp 發布:2025-02-05 02:43:08 瀏覽:123
阿里雲伺服器共享電腦 發布:2025-02-05 02:42:18 瀏覽:417
伺服器有多少台電腦 發布:2025-02-05 02:40:41 瀏覽:447
安卓手機為什麼最新微信安裝不了 發布:2025-02-05 02:31:03 瀏覽:106
安卓手機什麼時候開售 發布:2025-02-05 02:14:15 瀏覽:660
編程車模型 發布:2025-02-05 02:09:55 瀏覽:680
雅馬哈天劍哪個配置好 發布:2025-02-05 02:00:35 瀏覽:170
我的世界國際服推薦118伺服器 發布:2025-02-05 01:50:48 瀏覽:46
普通電腦做伺服器怎麼操作 發布:2025-02-05 01:46:22 瀏覽:628
原神為什麼同伺服器加不起好友 發布:2025-02-05 01:41:03 瀏覽:337