bada的系统事件

来源:互联网 发布:二叉树的遍历算法c加加 编辑:程序博客网 时间:2024/05/24 01:51

System Events

Application 类提供了处理如下系统事件的事件处理器

  • 电池事件(Battery events)
  • 内存事件(Memory events)
  • 屏幕事件(Screen events)

电池事件(Battery Events)

当电池电量等级改变时该事件被触发。像相机、MP3播放器这样耗电量大的多媒体应用需要检测电池电量等级。使用 OnBatteryLevelChanged()事件处理器来处理电池事件。 当电池电量等级改变时该处理器被调用。

根据电量,推荐下面的处理方式:

  • EMPTY:关闭应用程序。
  • CRITICAL:停止使用多媒体特性,因为在该电量等级下,不能保证他们能够正常使用。

OnBatteryLevelChanged()事件处理器的使用方法如下:

void MyApplication::OnBatteryLevelChanged(BatteryLevel batteryLevel){   // TODO:} 

内存事件(Memory Events)

当设备内存低时该事件被触发。当内存低或不足以运行一个应用时,在OnLowMemory() 事件处理器中从堆中释放不用的内存。

OnLowMemory() 事件处理器使用方法如下:

void MyApplication::OnLowMemory(void){   // TODO:} 

屏幕事件(Screen Events)

An application can receive screen events in OnScreenOn() andOnScreenOff()  event handlers if it registers a screen event listener. When theOnScreenOff() event  handler is triggered, the application must reduce power consumption by releasing  the activated resources, such as 3D, media, and sensors, which are no longer  used. The released resources can be acquired again when theOnScreenOn() event  handler is triggered.

You must handle the resources efficiently in the OnForeground(), OnBackground(), OnScreenOn(), andOnScreenOff()  event handlers. Be careful not to duplicate or delete  resources.

For example:

  • When the touch panel auto-lock mode is enabled in the device, the OnBackground() event  handler is called directly afterOnScreenOff().
  • When the backlight time expires, the OnScreenOff() event  handler is triggered. If the device is in the auto-lock mode,OnBackground() is  called after OnScreenOff() when the  lock UI is displayed.
  • When the unlock key is pressed, if the touch lock is enabled, OnScreenOn() is  triggered. TheOnForeground() event  handler is called after the lock UI disappears.
  • When the lock key is pressed, OnBackground() is  called after the lock UI is displayed. When the backlight turns off,OnScreenOff() is  called.

OnScreenOn()OnScreenOff() 事件处理器使用方法如下:

void MyApplication::OnScreenOn (void) {   //TODO:}   void MyApplication::OnScreenOff (void) {    //TODO:} 

For more information on system events, see the API  Reference.

原创粉丝点击