BREW的事件機制,BREW中的設計模式

來源:互聯網
上載者:User

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

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.