v0.6.2b: improved aspects of app lifecycle management
This commit is contained in:
committed by
Evan Debenham
parent
a248609df4
commit
553badc118
@@ -142,26 +142,54 @@ public class Game extends Activity implements GLSurfaceView.Renderer, View.OnTou
|
||||
view.setRenderer( this );
|
||||
view.setOnTouchListener( this );
|
||||
setContentView( view );
|
||||
|
||||
//so first call to onstart/onresume calls correct logic.
|
||||
paused = true;
|
||||
}
|
||||
|
||||
private boolean paused = false;
|
||||
private boolean paused;
|
||||
|
||||
//Checks for gingerbread are here due to minor activity lifecycle differences
|
||||
|
||||
@Override
|
||||
public void onStart() {
|
||||
super.onStart();
|
||||
|
||||
now = 0;
|
||||
paused = false;
|
||||
view.onResume();
|
||||
|
||||
Music.INSTANCE.resume();
|
||||
Sample.INSTANCE.resume();
|
||||
if (Build.VERSION.SDK_INT > Build.VERSION_CODES.GINGERBREAD_MR1){
|
||||
resumeGame();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onStop() {
|
||||
super.onStop();
|
||||
|
||||
if (Build.VERSION.SDK_INT > Build.VERSION_CODES.GINGERBREAD_MR1){
|
||||
pauseGame();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onResume() {
|
||||
super.onResume();
|
||||
|
||||
if (Build.VERSION.SDK_INT <= Build.VERSION_CODES.GINGERBREAD_MR1){
|
||||
resumeGame();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onPause() {
|
||||
super.onPause();
|
||||
|
||||
if (Build.VERSION.SDK_INT <= Build.VERSION_CODES.GINGERBREAD_MR1){
|
||||
pauseGame();
|
||||
}
|
||||
}
|
||||
|
||||
public void pauseGame(){
|
||||
if (paused) return;
|
||||
|
||||
if (scene != null) {
|
||||
scene.pause();
|
||||
}
|
||||
@@ -174,6 +202,22 @@ public class Game extends Activity implements GLSurfaceView.Renderer, View.OnTou
|
||||
Sample.INSTANCE.pause();
|
||||
}
|
||||
|
||||
public void resumeGame(){
|
||||
if (!paused) return;
|
||||
|
||||
now = 0;
|
||||
paused = false;
|
||||
view.onResume();
|
||||
|
||||
Music.INSTANCE.resume();
|
||||
Sample.INSTANCE.resume();
|
||||
}
|
||||
|
||||
public static void quitGame(){
|
||||
Game.instance.finish();
|
||||
System.exit(0);
|
||||
}
|
||||
|
||||
public boolean isPaused(){
|
||||
return paused;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user