SurfaceHolder.lockCanvas returns null if the surface is not in the foreground

I am currently testing LiveWallpaper on Android. I draw something on the canvas using code that looks something like this:

final SurfaceHolder holder = getSurfaceHolder();
Canvas c = new Canvas();
c = holder.lockCanvas(); // c becomes null
c.save();
c.drawBitmap(currentBitmap);
c.restore();
holder.unlockCanvasAndPost(c);

This part works fine under normal circumstances. However, I have a listener that executes this code whenever a parameter is changed in the settings corresponding to this service. It seems that whenever I execute this code from the settings activity, I get NullPointerby the method c.save().

It seems that only when the Wallpaper is not in the foreground, mount.lockCanvas (). Is it impossible to draw on this surface if it is not in the foreground?

0
source share
1

. - onPause onVisibilityChanged (false) onResume onVisibilityChanged (true), , .

. , , , , .

+2

All Articles