Android game goes blank after pressing home and restarting
- by sirconnorstack
I am making an Android game with an Activity called Game, a SurfaceView called GameView and a Thread called GameThread. The Game's onCreate(), I make a new GameView, which makes a new GameThread, where all the game logic and canvas drawing is carried out.
However, I'm having some lifecycle difficulties. When I press back and restart it, it works fine, but when I press home and restart it, all I see is a blank screen. Here are the GameView's onSurfaceCreated() and onSurfaceDestroyed():
@Override
public void surfaceCreated(SurfaceHolder holder) {
mThread.mRunning = true;
mThread.mWidth = getWidth();
if(mThread.mWidth > 550) mThread.mWidth = 550;
mThread.mHeight = getHeight();
try {
mThread.start();
} catch(IllegalThreadStateException e) {
}
}
@Override
public void surfaceDestroyed(SurfaceHolder holder) {
// Wait for the secondary thread to end before finishing
boolean retry = true;
mThread.mRunning = false;
while (retry) {
try {
mThread.join();
retry = false;
} catch (InterruptedException e) {
}
}
}