顯示具有 androidIntent 標籤的文章。 顯示所有文章
顯示具有 androidIntent 標籤的文章。 顯示所有文章

2012年2月20日 星期一

[AndroidIntent] Intent flags when launch App

By debug mode:
FLAG_ACTIVITY_NEW_TASK

From app list:
FLAG_ACTIVITY_NEW_TASK
FLAG_ACTIVITY_RESET_TASK_IF_NEEDED

From LRU:
FLAG_ACTIVITY_LAUNCHED_FROM_HISTORY
FLAG_ACTIVITY_NEW_TASK

2011年12月27日 星期二

[Android] Intent extra value

Intent intent = new Intent();
intent.putExtra("A", "x");
intent.putExtra("A", 1);
// value of key A will be int 1 finally.

// So if i want to get the String from key A it will have error!
String a = intent.getStringExtra("A");

2011年9月28日 星期三

[AndroidIntent] Intent Filter note

對一個android的應用程式而言,最重要的檔案是AndroidManifest.xml。它負責向下一層的framwork註冊該應用程式,包括此應用程式的名字,分組 (哪個category),用哪個icon,有什麼功能 (avtivity,service,broadcast receiver,content provider)等等。使得framework (package manager)接到通知 (intent)時,能夠根據目前系統註冊的情況,濾出符合條件的功能。


* Definition
  • Android 系統如何判斷哪個元件可以接收哪個 intent, 宣告在 AndroidManifest.xml 中。
  • 宣告元件時可加入的 Intent Filter 設定,屬性有 action, category, data,三個在一組內皆能有多個,只要符合三個各自條件,即通過此 intent-filter。
  • 每個元件內可以設定 0 ~ 多組 的 intent filter, 每一組的 Intent Filter 都是一份比對規則,只要通過一組即可。


* Process
當 intent 發出來時,系統會去檢查Manifest 內各元件內的intent filter, 而啟動適合的元件,若元件沒有設定filter,那就只能接收到有清楚指定 component 的 intent。


* action: 執行 intent 的方式。
  • 能有 0 ~ 多個。
  • 合格條件: intent 中的 action 為 intent-filter 宣告的之一。
    • 如果沒有宣告任何一個,因為 intent 沒得比對,所以沒有任何 intent 會符合;
    • 如果是 intent 沒有帶有 action,filter 中至少有宣告一個,即能通過此 filter。

* category: intent 的類別。
  • 能有 0 ~ 多個。
  • 合格條件: intent-filter 中必須完全符合 intent 中的 category。
    • intent-filter 宣告比 intent 中還多的 category 是不影響的。
    • i.e. intent 中沒有 category,即合格。
  • Default Category
    • 當執行 startActivity() 而使用沒有明確設定目標的 intent (implicit intent),Category 會預設為 Intent.CATEGORY_DEFAULT。
    • 因此,若 componen 需要接收 implicit intent,就必須在 intent filter 裡加上"android.intent.category.DEFAULT"。
    • 例外中的例外: 如果 filter 設定 "android.intent.action.MAIN" 和 "android.intent.category.LAUNCHER",則不需指定 DEFAULT 也可接收 implicit intent。

* data: intent 的資料類型。
  • 能有 0 ~ 多個。
  • 合格條件: intent 中的 data 為 intent-filter 宣告的之一。


. Updated on 2014/02/18


* Reference
- Android Intent Filter-判斷intent傳遞對象 - kei chueng - 博客园
- Intent Filter
- android -- 應用程式自我介紹之intent resolution @ 心的距離 :: 痞客邦 PIXNET ::
- <action>
- <category>
- <data>

2011年9月11日 星期日

[Android] Intent and PendingIntent

[Intent]
  • 是即時的,隨著其所在的 activity 消失而消失。
  • 提供 component 互相調用時的所需資訊,算是 caller 和 callee 間的橋樑 (?)。


[PendingIntent]
  • 用於處理即將發生的事,例如在 notificationManager 跳轉頁面,但不是馬上跳轉。
  • 包含了 Intent 的描述又是 Intent 行為的執行,如果將 Intent 比作成一個訂單的話,PendingIntent 像是一個下訂單的人,因为它既要負責將訂單發出去,也要負責訂單發送的處理,比如發送成功後要準備驗收訂定貨物,發送失敗後要重發送或是取消訂單等操作。
  • 主要包含的內容是要執行的 intent 和當時 component 的 context,可以看做是對 intent 再做包裝的結果。
  • 當前的 activity 並不能馬上使用 pendingIntent 所包含的 intent,而是在外部執行 pendingIntent 時,才去使用其中的intent,可以脫離 app 而存在。
  • 有就是 pendingIntent 中會保存前個 context of component (ex: A),讓後來調用的此 pendingIntent 的 component (ex: B),可以如在 A 中執行的使用此 pendingIntent 中的 intent,所以即使 A 已不存在,還是能透過保存在 pendingIntent 中的 context 執行 intent。
  • 可透過getActivity(), getBroadcast(), getService() 得到。
  • ex: 常使用在 alertManager and notificationManager。



* Reference
- Intent和PendingIntent的区别详细分析 | 无锋网
- 深入学习android之AlarmManager - Java-Jinguo - ITeye技术网站
- Android Intent学习 | 好你 - 你好,Google Android 2.2学习笔记