BREW的事件機制
2007/03/08 10:47 A.M.
Brew中的handle event函數都是boolean傳回型別的,這是為了實現事件處理的層次機制,當該層上的handle event沒有處理該事件時,應該返回false,以便上層對該事件感興趣的handle event來處理。如果處理了,應該返回TRUE,說明該事件已被處理,無需其他層再處理。
下面給出完整的BREW環境下訊息分發和處理的流程。
首先BREW存在於一個task中,儘管允許brew運行於一個單獨的task中,但是實際oem中都是將其運行於現有的一個task中,比如ui task。當brew運行後,首先ui task中捕捉到各種事件,此時ui task通過aee_dispatch將事件分發至brew環境中,brew環境再通過aee_sentevent具體分發事件至目的地。接著在兩種不同的情況下將走不同的流程。
如果當前沒有active dialog,則緊接著IAPPLET_Handleevent被brew自動調用來處理事件,而此時調用的IAPPLET_Handleevent其實就是使用者註冊的自己的applet_handleevent。從而實現了允許使用者app捕捉到事件並處理的機制。在使用者的app handleevent中,使用者可以將事件繼續下發,比如通過調用IMENU_handleevent等將事件下發給各種控制項處理。
如果當前有active dialog,則緊接著Adialog_event被brew自動調用,從而使得事件被dialog最先截獲,而dialog之後的處理是檢查包含的控制項中哪個處於focus,並將事件下發給它的handleevent來處理,同時根據其傳回值來判斷其是否已經處理了該事件,當其返回False後,dialog將該事件繼續轉寄至該dialog註冊的handleevent(如果有的話),如果該handleevent仍然返回false,brew繼續將該事件轉寄至app handleevent。這種機制使得當以dialog方式來建立應用時,各種event被自動的處理,從而簡化了代碼量,但也使得事件流程更加晦澀,使用者的程式不能直接的控制它。
Handling SUSPEND and RESUME events
It is important to include the EVT_APP_SUSPEND and EVT_APP_RESUME events withinyour application’s HandleEvent function so that your application knows how to handle eventsthat might interrupt its operation. For example, when an SMS message or an incoming phonecall is received, you application needs to know whether it should resume where it left off at theend of the call or if it should start over.
When BREW suspends an applet, it sends the EVT_APP_SUSPEND event. Depending onthe type of application you are developing, you have a couple of options on how BREWshouldhandle the event, as follows:
You can set the applet to return TRUE to the event, indicating that the applet has processed the Suspend and
has not been unloaded from memory. This is howMyFirstApp works.
You can also have the applet return FALSE to the event, indicating that you do notwant the applet to process the Suspend. When this occurs, BREW sends anEVT_APP_STOP event and the applet is removed from memory.
BREW中的設計模式
原廠模式
1. 原廠模式介紹
2. BREW中的IShell_CreateInstance
SingleTon模式
1. SingleTon模式
2. BREW中SingleTon的不同實現方式和注意事項
3. SingleTon/Multi-Instance的使用場合
4. SingleTon中如何儲存應用關聯的非共用資料
5. Multi-Instance中如何進行局部共用
Facade模式
1. Facade模式介紹
2. BREW是手機軟體的Facade
Proxy模式
1. Proxy模式介紹
2. BMP中的Stub/skelecton
Observer模式
1. Observer模式介紹
2. BREW中的Model-Listener
3. BREW中的Notifier