Screen rotation Live Wallpaper

I am currently working on live wallpapers that are very intense and do not handle screen rotation very well.

In fact, the wallpaper is destroyed and a blank screen is displayed without calling onSurfaceChanged!

Here is what I have in 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 sure that this method is not called because there is no log message.

Why is this happening and what are the methods for processing screen rotation? Could it be that my live wallpapers are so intense that the void cannot be called?

In addition, onVisibilityChanged is also not called, and when I open the applications 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);
        }
    }
+5
source share
1 answer

In your manifest declare:

    <activity android:name=".YourActivityName"
              android:configChanges="keyboardHidden|orientation"
    </activity>

onSurfaceChanged - , configChanges - !

: onVisibilityChanged - , :

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.

, "" onPause() onResume()

+1

All Articles