how to pause and resume a surfaceView thread

The easy solution is to simply kill and restart the thread. Create methods resume() – creates thread object and starts it – and pause() – kills thread (see Lunarlander example) – in your SurfaceView class and call these from surfaceCreated and surfaceDestroyed to start and stop the thread.

Now in the Activity that runs the SurfaceView, you will also need to call the resume() and pause() methods in the SurfaceView from the Activity’s (or fragment’s) onResume() and onPause(). It’s not an elegant solution, but it will work.

Leave a Comment