java - How to freeze the last frame of an animation in a SurfaceView? -


i'm drawing on surfaceview using thread has following calssic run() method:

@override public void run() {     while (mrun) {         canvas canvas = null;         synchronized (msurfaceholder) {                 try {                     canvas = msurfaceholder.lockcanvas();                     update();                     dodraw(canvas);                 } {                     if (canvas != null) {                         msurfaceholder.unlockcanvasandpost(canvas);                     }                 }         }     } } 

i wanted save work if next frames drawn moment on, same previous one, skipped ondraw, got flickering issues due double buffering mechanism. went on , did this:

@override public void run() {     while (mrun) {         canvas canvas = null;         synchronized (msurfaceholder) {             if (misanimating) {          // <---- ma! flag!!!                 try {                     canvas = msurfaceholder.lockcanvas();                     update();                     dodraw(canvas);                 } {                     if (canvas != null) {                         msurfaceholder.unlockcanvasandpost(canvas);                     }                 }             }         }     } } 

if turn off misanimating flag, stopping run loop locking canvas , drawing on it, worked charm - did animation , after finished, freeze drawing cycle , keep animation's last frame on screen.

but had go , see following android docs:

the content of surface never preserved between unlockcanvas() , lockcanvas(), reason, every pixel within surface area must written. exception rule when dirty rectangle specified, in case, non-dirty pixels preserved.

so... how come code works?

i think 1 of 2 things happening, first (very unlikely) might accidentally drawing last frame of animation repeatedly, if not, means surfaceview not being invalidated change on view hence keeping cached last buffer of pixels showed, in order test it, set button on screen , when surfaceview gets "frozen" tap on button , make button gone, force redraw on elements on screen, if animation dissapears mean being cached...

regards!


Comments

Popular posts from this blog

Unable to remove the www from url on https using .htaccess -