bada的系统事件

阅读更多

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() and OnScreenOff() event handlers if it registers a screen event listener. When the OnScreenOff() 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 the OnScreenOn() event handler is triggered.

You must handle the resources efficiently in the OnForeground(), OnBackground(), OnScreenOn(), and OnScreenOff() 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 after OnScreenOff().
  • 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. The OnForeground() 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.

你可能感兴趣的:(Bada,UI)