Skip to content Skip to sidebar Skip to footer

SurfaceHolder.lockCanvas() Returning Null

I'm making a game, and since I'm new to Android, I based the design off of the example LunarLander code. In its design, GameThread.doStart() is called from GameActivity, and the th

Solution 1:

You are starting a thred in activity on create, while it should be started only when the SurfaceView is created and ready. Check this the second, the SurfaceView example: How can I use the animation framework inside the canvas?


Solution 2:

Start running the thread once the surface gets created. i.e. when you get a callback surfaceCreated(), start the thread.

Code Snippet

public void surfaceCreated(SurfaceHolder holder) {
    thread.setRunning(true);
    thread.start();
}

Shash


Post a Comment for "SurfaceHolder.lockCanvas() Returning Null"