我試圖讓我的程序使用更少的資源,當我通過覆蓋onClose()
函數將其發送到背景時。我的第一步是停止繪製文本和計量字段。isForeground()和onExposed和onObscured之間的區別
我一直在閱讀效率這個文檔, "Eliminating unnecessary processing on the device"
「可以使用的方法來停止動畫或重繪屏幕時,屏幕是不可見的,並且當屏幕再次顯示恢復。您可以覆蓋Screen.onExposed(),當您的應用程序的屏幕位於顯示堆棧頂部並顯示給用戶時,可以調用該屏幕。您可以覆蓋Screen.onObscured(),當您的應用程序屏幕未顯示給用戶或被另一個屏幕遮擋。「
我知道如果我使用isForeground()
,它會從繪畫,如果我的應用程序在後臺阻止它,但它會做同樣的,如果它是由另一個應用程序掩蓋?它似乎更容易使用isForeground()
private boolean isExposed;
protected void onExposed()
{
isExposed = true;
}
protected void onObscured()
{
isExposed = false;
}
public void batteryStatusChange(int status)
{
// TODO Auto-generated method stub
if ((status & DeviceInfo.BSTAT_LEVEL_CHANGED) != 0)
{
//is there a difference between the two if's?
//if(isExposed)
//if(UiApplication.getUiApplication().isForeground())
{
batteryStatusField.setText(getBatteryLevel());
bitGauge6.setValue(DeviceInfo.getBatteryLevel());
}
}
}
public boolean onClose()
{
UiApplication.getUiApplication().requestBackground();
return true;
}
是否設置文本字段的文本和計量器字段的級別**所有**在您的'batteryStatusChange'回調被調用時發生?如果是這樣,我認爲你不需要擔心資源使用。 – Nate