Android turn off screen without restarting game -


i'm trying create android game, having problem turning off screen.

currently game works when press home button pauses , when press button stops , later starts again.

now noticed when press power button turn off screen stops game, without closing, , when turn screen on restarted. prevent , make game pause when turn off screen,

my current code:

public void surfacecreated(surfaceholder holder) {     if (!mgameisrunning) {         mgameisrunning = true;         loop = new gameloop(getholder(), this);         createsprites();         loop.setrunning(true);         loop.start();      } else {         resume();     }  }  public void surfacedestroyed(surfaceholder holder) {     pause(); }  public void pause() {     loop.setrunning(false);     while (true) {         try {             loop.join();         } catch (interruptedexception e) {         }         break;     }     loop = null; }  public void resume() {     loop = new gameloop(getholder(), this);     loop.setrunning(true);     loop.start(); } 

it application losing opengl context , has restart when re-open it. remember it, context saved time if use 'home' button, dropped when use either button or put device sleep.

you try use 'home' button , leave in background time, tests this: 'home' button -> instantly switch works. try give time context drop.

again, i'm not sure. has been while me since have done android programming.


Comments

Popular posts from this blog

Eclipse formatter for java ending braces -

ruby - Nesting modules inside of a Rails eninge gem -

java - Are there any classes that implement javax.persistence.Parameter<T>? -