I am currently working on a live wallpaper that is very intensive and does not handle screen rotation very well.
In fact the wallpaper is destroyed and displays a blank screen without calling onSurfaceChanged!
Here is what I have within the onSurfaceChanged method:
@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);
}
I am positive this method does not get called because there is no log message.
Why is this happening and what are some techniques for handling screen rotation? Could it be that my live wallpaper is so intensive the void cannot be called?
Also, onVisibilityChanged is not called as well and when I open apps on the emulator, there is no log message:
@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);
}
}
In your manifest, declare:
<activity android:name=".YourActivityName"
android:configChanges="keyboardHidden|orientation"
</activity>
Your onSurfaceChanged
-method be only be called if declare theconfigChanges
-attribute in the manifest!
Regarding your second issue: onVisibilityChanged
is not what you would expect from the name:
Called when the window containing has change its visibility (between GONE, INVISIBLE, and VISIBLE). Note that this tells you whether or not your window is being made visible to the window manager; this does not tell you whether or not your window is obscured by other windows on the screen, even if it is itself visible.
You need to check whether your app is "visible" to the user via onPause()
and onResume()
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With