yuyashuai / FrameAnimation

High-Performance Frame Animation Library For Android

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

关于动画执行过程,home键退出再次进入时,报错

pys200603027 opened this issue · comments

11-21 12:50:54.120 4760-4832/com.yuyashuai.surfaceviewanimation E/SurfaceHolder: Exception locking surface
                                                                                 java.lang.IllegalArgumentException: Surface was already locked
                                                                                     at android.view.Surface.lockCanvas(Surface.java:262)
                                                                                     at android.view.SurfaceView$4.internalLockCanvas(SurfaceView.java:826)
                                                                                     at android.view.SurfaceView$4.lockCanvas(SurfaceView.java:794)
                                                                                     at com.yuyashuai.surfaceanimation.SurfaceViewAnimation$MyCallBack.clearSurface(SurfaceViewAnimation.java:324)
                                                                                     at com.yuyashuai.surfaceanimation.SurfaceViewAnimation$MyCallBack.drawBitmap(SurfaceViewAnimation.java:307)
                                                                                     at com.yuyashuai.surfaceanimation.SurfaceViewAnimation$MyCallBack.access$1600(SurfaceViewAnimation.java:261)
                                                                                     at com.yuyashuai.surfaceanimation.SurfaceViewAnimation$MyCallBack$1.run(SurfaceViewAnimation.java:345)
11-21 12:50:54.220 4760-4832/com.yuyashuai.surfaceviewanimation E/AndroidRuntime: FATAL EXCEPTION: Thread-3543
                                                                                  Process: com.yuyashuai.surfaceviewanimation, PID: 4760
                                                                                  java.lang.NullPointerException: Attempt to invoke virtual method 'void android.graphics.Canvas.drawColor(int, android.graphics.PorterDuff$Mode)' on a null object reference
                                                                                      at com.yuyashuai.surfaceanimation.SurfaceViewAnimation$MyCallBack.clearSurface(SurfaceViewAnimation.java:326)
                                                                                      at com.yuyashuai.surfaceanimation.SurfaceViewAnimation$MyCallBack.drawBitmap(SurfaceViewAnimation.java:307)
                                                                                      at com.yuyashuai.surfaceanimation.SurfaceViewAnimation$MyCallBack.access$1600(SurfaceViewAnimation.java:261)
                                                                                      at com.yuyashuai.surfaceanimation.SurfaceViewAnimation$MyCallBack$1.run(SurfaceViewAnimation.java:345)

没有考虑到SurfaceView进入后台的情况,最近我会尽力补上去,如果不影响你的业务逻辑的话,可以暂时在Activity的onPause方法中判断,如果动画在执行调用anmation.stop()方法防止这种crash

好的,surfaceview的销毁带来了一些不方便,比如

  1. 后台时会执行onDestroy
  2. 锁屏的时候不会执行onDestroy

onPause我试试,感谢作者的热心