Surfaceholder.lockcanvas Returns Null If The Surface Is Not In The Foreground
I'm currently doing a test with a LiveWallpaper in Android. I am drawing something on the canvas using code that looks something like this: final SurfaceHolder holder = getSurfaceH
Solution 1:
That's right. A common way to avoid this is to unregister your listener in onPause or onVisibilityChanged(false), and reregister in onResume or onVisibilityChanged(true), since you shouldn't react to settings changes when your canvas isn't visible.
Another solution would be to simply surround that section of code with a null check, and forget about it. I'd recommend against this, though, since what you really want to do is prevent your code from even attempting to draw to the surface when it's not in view.
Post a Comment for "Surfaceholder.lockcanvas Returns Null If The Surface Is Not In The Foreground"