我正在为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,动态壁纸选择器根本不会崩溃。是否可以仅为活动“动态壁纸选择器”编辑动态壁纸行为?