Polarbear0106 Polarbear0106 - 6 months ago 10
Android Question

Issues when reopening app after locking and unlocking phone

In my game, I have a thread. This thread is paused in onPause() in the activity and restarted in surfaceCreated in the main game class.

public void surfaceCreated(SurfaceHolder holder) {
if(gt == null) {
gt = new GameThread(getHolder(), this);


The onPause(called from game)

public void onPause(){
... other stuff
if(gt != null){
try {
gt = null;
}catch(Exception e){


But for some reason, when the screen is locked and unlocked, the thread does not start again. But when I open the log of all used apps(not sure what it is called) and reopen the app from there the thread restarts. Why is this happening and how can I solve it? It is really annoying because the onTouch logic works but nothing is updated(images, textviews)


You should start your thread in onStart(), not in surfaceCreated, because the surface is not recreated in this case (your activity is not destroyed), so the method surfaceCreated is not called when you unlock your phone. However, onStart() is.