I am using a SurfaceView and a rendering thread to develop a game based on structure like LunarLander.
However, I faced many problems, and here I want to point them
I hope it can help
@Override
public void surfaceCreated(SurfaceHolder holder) {
//if it is the first time the thread starts
if(thread.getState() == Thread.State.NEW){
thread.setRunning(true);//riga originale
thread.start();//riga originale
}
//after a pause it starts the thread again
else
if (thread.getState() == Thread.State.TERMINATED){
thread = new MainThread(getHolder(), this);
thread.setRunning(true);
thread.start(); // Start a new thread
}
}
and this
@Override
protected void onPause() {
Log.d(TAG, "Pausing...");
MainThread.running=false;//this is the value for stop the loop in the run()
super.onPause();
}