在动态壁纸选择器 Android 3.0 中旋转设备时出现 IllegalArgumentException

发布于 2024-11-26 03:30:23 字数 3806 浏览 1 评论 0原文

我正在为 Honeycomb 3.0 开发动态壁纸,但出现随机错误。

当我处于壁纸选择器(带有“设置壁纸”和“设置...”按钮的窗口,以了解)并且显示动态壁纸时,如果我旋转设备,壁纸应该重新加载配置适应新的方向。有时会,有时会崩溃。

该错误在某种程度上与 BaseSurfaceHolder.unlockCanvasAndPost 方法相关,但我真的不知道问题所在。我认为它无法正确加载某些资源。

以下是错误日志:

07-21 16:07:38.490: WARN/WindowManager(292): java.lang.IllegalArgumentException: Requested window android.os.BinderProxy@40d19f28 does not exist
07-21 16:07:38.490: WARN/WindowManager(292):     at com.android.server.wm.WindowManagerService.windowForClientLocked(WindowManagerService.java:6731)
07-21 16:07:38.490: WARN/WindowManager(292):     at com.android.server.wm.WindowManagerService.windowForClientLocked(WindowManagerService.java:6722)
07-21 16:07:38.490: WARN/WindowManager(292):     at com.android.server.wm.WindowManagerService.removeWindow(WindowManagerService.java:2414)
07-21 16:07:38.490: WARN/WindowManager(292):     at com.android.server.wm.Session.remove(Session.java:149)
07-21 16:07:38.490: WARN/WindowManager(292):     at android.view.IWindowSession$Stub.onTransact(IWindowSession.java:120)
07-21 16:07:38.490: WARN/WindowManager(292):     at com.android.server.wm.Session.onTransact(Session.java:111)
07-21 16:07:38.490: WARN/WindowManager(292):     at android.os.Binder.execTransact(Binder.java:320)
07-21 16:07:38.490: WARN/WindowManager(292):     at dalvik.system.NativeStart.run(Native Method)
07-21 16:07:38.490: ERROR/AndroidRuntime(20768): FATAL EXCEPTION: main
07-21 16:07:38.490: ERROR/AndroidRuntime(20768): java.lang.IllegalArgumentException
07-21 16:07:38.490: ERROR/AndroidRuntime(20768):     at android.view.Surface.unlockCanvasAndPost(Native Method)
07-21 16:07:38.490: ERROR/AndroidRuntime(20768):     at com.android.internal.view.BaseSurfaceHolder.unlockCanvasAndPost(BaseSurfaceHolder.java:215)
07-21 16:07:38.490: ERROR/AndroidRuntime(20768):     at mx.livewallpaper.clock.CubeWallpaper1$CubeEngine.drawFrame(CubeWallpaper1.java:686)
07-21 16:07:38.490: ERROR/AndroidRuntime(20768):     at mx.livewallpaper.clock.CubeWallpaper1$CubeEngine$1.run(CubeWallpaper1.java:292)
07-21 16:07:38.490: ERROR/AndroidRuntime(20768):     at android.os.Handler.handleCallback(Handler.java:587)
07-21 16:07:38.490: ERROR/AndroidRuntime(20768):     at android.os.Handler.dispatchMessage(Handler.java:92)
07-21 16:07:38.490: ERROR/AndroidRuntime(20768):     at android.os.Looper.loop(Looper.java:132)
07-21 16:07:38.490: ERROR/AndroidRuntime(20768):     at android.app.ActivityThread.main(ActivityThread.java:4028)
07-21 16:07:38.490: ERROR/AndroidRuntime(20768):     at java.lang.reflect.Method.invokeNative(Native Method)
07-21 16:07:38.490: ERROR/AndroidRuntime(20768):     at java.lang.reflect.Method.invoke(Method.java:491)
07-21 16:07:38.490: ERROR/AndroidRuntime(20768):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:844)
07-21 16:07:38.490: ERROR/AndroidRuntime(20768):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:602)
07-21 16:07:38.490: ERROR/AndroidRuntime(20768):     at dalvik.system.NativeStart.main(Native Method)
07-21 16:07:38.500: ERROR/android.os.Debug(292): Dumpstate > /data/log/dumpstate_app_error

编辑:下面的代码是第 686 行的 drawFrame() 方法:

void drawFrame() {
            final SurfaceHolder holder = getSurfaceHolder();

            Canvas c = null;
            try {
                c = holder.lockCanvas();
                if (c != null) {

                    drawLogo3(c);
                }
            } finally {
                if (c != null) holder.unlockCanvasAndPost(c);
            }

这是所有动态壁纸中存在的默认方法,我从 Android SDK 的 CubeWallpaper 动态壁纸示例中获取了它。

编辑2:

听起来像是缓冲区错误。如果我将帧速率设置为 10fps 而不是 40fps,动态壁纸选择器根本不会崩溃。是否可以仅为活动“动态壁纸选择器”编辑动态壁纸行为?

I'm developing a Live Wallpaper for Honeycomb 3.0, but I get a random error.

When I'm in wallpaper picker (the window with "Set Wallpaper" and "Settings..." buttons, to understand) and Live Wallpaper is displayed, if I rotate the device, the wallpaper should reload with the configuration adapted for new orientation. Sometimes it does, sometimes it crashes.

The error is in some way related to BaseSurfaceHolder.unlockCanvasAndPost method, but I really don't know were is the issue. I think it cannot load correctly some resources..

Here's error log:

07-21 16:07:38.490: WARN/WindowManager(292): java.lang.IllegalArgumentException: Requested window android.os.BinderProxy@40d19f28 does not exist
07-21 16:07:38.490: WARN/WindowManager(292):     at com.android.server.wm.WindowManagerService.windowForClientLocked(WindowManagerService.java:6731)
07-21 16:07:38.490: WARN/WindowManager(292):     at com.android.server.wm.WindowManagerService.windowForClientLocked(WindowManagerService.java:6722)
07-21 16:07:38.490: WARN/WindowManager(292):     at com.android.server.wm.WindowManagerService.removeWindow(WindowManagerService.java:2414)
07-21 16:07:38.490: WARN/WindowManager(292):     at com.android.server.wm.Session.remove(Session.java:149)
07-21 16:07:38.490: WARN/WindowManager(292):     at android.view.IWindowSession$Stub.onTransact(IWindowSession.java:120)
07-21 16:07:38.490: WARN/WindowManager(292):     at com.android.server.wm.Session.onTransact(Session.java:111)
07-21 16:07:38.490: WARN/WindowManager(292):     at android.os.Binder.execTransact(Binder.java:320)
07-21 16:07:38.490: WARN/WindowManager(292):     at dalvik.system.NativeStart.run(Native Method)
07-21 16:07:38.490: ERROR/AndroidRuntime(20768): FATAL EXCEPTION: main
07-21 16:07:38.490: ERROR/AndroidRuntime(20768): java.lang.IllegalArgumentException
07-21 16:07:38.490: ERROR/AndroidRuntime(20768):     at android.view.Surface.unlockCanvasAndPost(Native Method)
07-21 16:07:38.490: ERROR/AndroidRuntime(20768):     at com.android.internal.view.BaseSurfaceHolder.unlockCanvasAndPost(BaseSurfaceHolder.java:215)
07-21 16:07:38.490: ERROR/AndroidRuntime(20768):     at mx.livewallpaper.clock.CubeWallpaper1$CubeEngine.drawFrame(CubeWallpaper1.java:686)
07-21 16:07:38.490: ERROR/AndroidRuntime(20768):     at mx.livewallpaper.clock.CubeWallpaper1$CubeEngine$1.run(CubeWallpaper1.java:292)
07-21 16:07:38.490: ERROR/AndroidRuntime(20768):     at android.os.Handler.handleCallback(Handler.java:587)
07-21 16:07:38.490: ERROR/AndroidRuntime(20768):     at android.os.Handler.dispatchMessage(Handler.java:92)
07-21 16:07:38.490: ERROR/AndroidRuntime(20768):     at android.os.Looper.loop(Looper.java:132)
07-21 16:07:38.490: ERROR/AndroidRuntime(20768):     at android.app.ActivityThread.main(ActivityThread.java:4028)
07-21 16:07:38.490: ERROR/AndroidRuntime(20768):     at java.lang.reflect.Method.invokeNative(Native Method)
07-21 16:07:38.490: ERROR/AndroidRuntime(20768):     at java.lang.reflect.Method.invoke(Method.java:491)
07-21 16:07:38.490: ERROR/AndroidRuntime(20768):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:844)
07-21 16:07:38.490: ERROR/AndroidRuntime(20768):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:602)
07-21 16:07:38.490: ERROR/AndroidRuntime(20768):     at dalvik.system.NativeStart.main(Native Method)
07-21 16:07:38.500: ERROR/android.os.Debug(292): Dumpstate > /data/log/dumpstate_app_error

EDIT: code below is the drawFrame() method at line 686:

void drawFrame() {
            final SurfaceHolder holder = getSurfaceHolder();

            Canvas c = null;
            try {
                c = holder.lockCanvas();
                if (c != null) {

                    drawLogo3(c);
                }
            } finally {
                if (c != null) holder.unlockCanvasAndPost(c);
            }

It's a default method ppresent in all live wallpapers, I took it from CubeWallpaper Live Wallpaper Sample from Android SDK.

EDIT 2:

It sounds like a buffer error. If I set the framerate to 10fps instead of 40fps, the Live Wallpaper Picker doesn't crash at all. Is it possible to edit Live Wallpaper behaviour only for the Activity "Live Wallpaper Picker"?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

赤濁 2024-12-03 03:30:23

在破坏表面之前先连接螺纹

@Override
public void onSurfaceDestroyed(SurfaceHolder holder)
{
    try 
    {
        updater.join();
    } 
    catch (InterruptedException e) 
    {

    }
    super.onSurfaceDestroyed(holder);
}

have the thread join before you destroy the surface

@Override
public void onSurfaceDestroyed(SurfaceHolder holder)
{
    try 
    {
        updater.join();
    } 
    catch (InterruptedException e) 
    {

    }
    super.onSurfaceDestroyed(holder);
}
淡写薰衣草的香 2024-12-03 03:30:23

当你改变设备的方向时,函数“onsurfacechange()”被调用。你必须在那里做一些事情。我猜当你改变方向时,“surfaceholder”也改变了。我这样做:

@Override
        public void onSurfaceChanged(SurfaceHolder holder, int format,
                int width, int height) {
                        int lockwidth = 0;
            int lockheight = 0;
            mholder = holder;
            try {

                canvas = mholder.lockCanvas();
                lockwidth = canvas.getWidth();
                lockheight = canvas.getHeight();
                if (width > height) {
                    Utils.Width = lockheight;
                    Utils.screenWidth = lockheight;
                    Utils.screenHeight = lockwidth;
                    Utils.isWidth = true;
                    if (width == 1280 && height == 720 && lockwidth == 800
                            && lockheight == 480) {
                        Utils.screenWidth = 480;
                        Utils.screenHeight = 854;
                    }
                } else {
                    Utils.Width = lockwidth;
                    Utils.screenWidth = lockwidth;
                    Utils.screenHeight = lockheight;
                    Utils.isWidth = false;
                    if (width == 720 && height == 1280 && lockwidth == 480
                            && lockheight == 800) {
                        Utils.screenWidth = 480;
                        Utils.screenHeight = 854;
                    }
                }
                mholder.unlockCanvasAndPost(canvas);
            } catch (Exception e) {
            }
            Utils.rateX = (float) Utils.Width / (float) Utils.FLA_Width;
            Utils.ratio = Utils.screenWidth / Utils.FLA_Width;
            Utils.Width = lockwidth;
            Utils.Height = lockheight;
        }

when you change the orientation of device,the function "onsurfacechange()" called.you must do somthing there.I guess the when you change the orientant the "surfaceholder"also changed.I do it like :

@Override
        public void onSurfaceChanged(SurfaceHolder holder, int format,
                int width, int height) {
                        int lockwidth = 0;
            int lockheight = 0;
            mholder = holder;
            try {

                canvas = mholder.lockCanvas();
                lockwidth = canvas.getWidth();
                lockheight = canvas.getHeight();
                if (width > height) {
                    Utils.Width = lockheight;
                    Utils.screenWidth = lockheight;
                    Utils.screenHeight = lockwidth;
                    Utils.isWidth = true;
                    if (width == 1280 && height == 720 && lockwidth == 800
                            && lockheight == 480) {
                        Utils.screenWidth = 480;
                        Utils.screenHeight = 854;
                    }
                } else {
                    Utils.Width = lockwidth;
                    Utils.screenWidth = lockwidth;
                    Utils.screenHeight = lockheight;
                    Utils.isWidth = false;
                    if (width == 720 && height == 1280 && lockwidth == 480
                            && lockheight == 800) {
                        Utils.screenWidth = 480;
                        Utils.screenHeight = 854;
                    }
                }
                mholder.unlockCanvasAndPost(canvas);
            } catch (Exception e) {
            }
            Utils.rateX = (float) Utils.Width / (float) Utils.FLA_Width;
            Utils.ratio = Utils.screenWidth / Utils.FLA_Width;
            Utils.Width = lockwidth;
            Utils.Height = lockheight;
        }
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文