动态壁纸崩溃,下面的代码
public void render(){ Canvas canvas = null; try{ canvas = this._surfaceHolder.lockCanvas(null); synchronized (this._surfaceHolder) { this.onDraw(canvas); } }catch(Exception e){ Log.w("Surface holder ",e.toString());} finally{ if(canvas != null){ this._surfaceHolder.unlockCanvasAndPost(canvas); } } } protected void onDraw(Canvas canvas) { this.renderBackGround(canvas); for (Renderable renderable : this._fishes) { renderable.render(canvas); } };
崩溃与以下错误
06-07 19:49:09.143:E / SurfaceTextureClient(13629):queueBuffer:到SurfaceTexture的错误排队缓冲区,-19
06-07 19:49:09.143:E / SurfaceTextureClient(13629):
queueBuffer(handle = 0x1c1b30)Failed(No such device)
06-07 19:49:09.143:W / dalvikvm(13629):threadid = 11:线程退出与未捕获的异常(组= 0x40c671f8)
06-07 19:49:09.143:E / AndroidRuntime(13629):
致命例外:Thread-692
06-07 19:49:09.143:E / AndroidRuntime(13629):java.lang.IllegalArgumentException
06-07 19:49:09.143:E / AndroidRuntime(13629):android.view.Surface.unlockCanvasAndPost(Native Method)
06-07 19:49:09.143:E / AndroidRuntime(13629):在com.android.internal.view.BaseSurfaceHolder.unlockCanvasAndPost(BaseSurfaceHolder.java:215)
提前致谢
解决方法
当您在动态壁纸选择器中旋转设备时,通常会发生这种情况.我发现唯一的解决方案是捕获IllegalArgumentException并忽略它.
if (canvas != null) { try { holder.unlockCanvasAndPost(canvas); } catch (IllegalArgumentException e) { // Ignore weird bug when rotating in live wallpaper picker } }