Application 类提供了处理如下系统事件的事件处理器
当电池电量等级改变时该事件被触发。像相机、MP3播放器这样耗电量大的多媒体应用需要检测电池电量等级。使用 OnBatteryLevelChanged() 事件处理器来处理电池事件。 当电池电量等级改变时该处理器被调用。
根据电量,推荐下面的处理方式:
OnBatteryLevelChanged() 事件处理器的使用方法如下:
void MyApplication::OnBatteryLevelChanged(BatteryLevel batteryLevel) { // TODO: }
当设备内存低时该事件被触发。当内存低或不足以运行一个应用时,在OnLowMemory()事件处理器中从堆中释放不用的内存。
OnLowMemory() 事件处理器使用方法如下:
void MyApplication::OnLowMemory(void) { // TODO: }
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:
OnScreenOn() 和 OnScreenOff()事件处理器使用方法如下:
void MyApplication::OnScreenOn (void)
{
//TODO:
}
void MyApplication::OnScreenOff (void)
{
//TODO:
}
For more information on system events, see the API Reference.