我目前正在开发一款非常占用资源的动态壁纸,但是它不能很好地处理屏幕旋转。
事实上,在没有调用onSurfaceChanged方法的情况下,该壁纸会被销毁并显示一个空白屏幕!
以下是我在onSurfaceChanged方法中的代码:
@Override
public void onSurfaceChanged(SurfaceHolder holder, int format,
int width, int height) {
// TODO Auto-generated method stub
super.onSurfaceChanged(holder, format, width, height);
mRatio = (float) width / height;
if (mRatio > 1) {
orientation = 0;
}
if (mRatio < 1) {
orientation = 1;
}
setRunning(true);
Log.i(TAG, "Screen Rotation...");
mHandle.post(r);
}
我确定这个方法没有被调用,因为没有日志信息。
为什么会出现这种情况,有什么处理屏幕旋转的技巧吗? 难道是我的动态壁纸太过繁重,void无法被调用?
此外,onVisibilityChanged也没有被调用,当我在模拟器上打开应用时,也没有日志信息:
@Override
public void onVisibilityChanged(boolean visible) {
// TODO Auto-generated method stub
super.onVisibilityChanged(visible);
if (visible) {
setRunning(true);
Log.i(TAG, "Visible...");
mHandle.postDelayed(r, 2000);
} else {
setRunning(false);
Log.i(TAG, "Invisible...");
mHandle.removeCallbacks(r);
}
}