Android意圖是一個要執行的操作的抽象描述,它可以通過 startActivity 來啟動一個活動,broadcastIntent 來發送廣播到任何對它感興趣的廣播接受器組件,startService(Intent) 或者bindService(Intent, ServiceConnection, int) 來與后臺服務通訊, 意圖本身(一個 Intent 物件)是一個被動的資料結構,保存著要執行操作的抽象描述, 例如,你有一個活動,需要在 Android 設備上通過瀏覽器打開一個URL,為了這個目的,你的活動發送 ACTION_WEB_SEARCH 意圖到 Android 意圖處理器來在瀏覽器中打開給定的 URL ,意圖處理器通過決議一系列活動,并選擇最適合你的意圖的一個活動,在這個例子中,是 Web 瀏覽器活動,意圖處理器傳遞你的網頁地址到 Web 瀏覽器,并打開 Web 瀏覽器活動,
val q = "https://www.baidu.com" val intent = Intent(Intent.ACTION_WEB_SEARCH) intent.putExtra(SearchManager.QUERY, q) startActivity(intent)
public class Intent implements Parcelable, Cloneable{ 位于 android.content 包,常用構造器如下:
public Intent() public Intent(String action) public Intent(String action, Uri uri)
轉載請註明出處,本文鏈接:https://www.uj5u.com/yidong/429281.html
標籤:其他
上一篇:意圖(Intent)
