I do not think this part is necessary:
synchronized (mPauseLock) { while (!running) { try { mPauseLock.wait(); } catch (InterruptedException e) { } } }
If you use this, you will need to notify the lock release wait (); But try to use the same code without synchronized (mPauseLock)
EDIT:
The solution to the problem when you press the "Home" button, the application crashes:
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); gameView = new GameView(this); setContentView(gameView); } @Override public void onPause(){ super.onPause(); gameView.gameLoopThread.setRunning(false); finish(); }
And in GameView (SurfaceView) create a constructor:
public GameLoopThread gameLoopThread; public GameView(Context context) { super(context); gameLoopThread = new GameLoopThread(this); }
Carnal source share