v0.6.2b: improved aspects of app lifecycle management
This commit is contained in:
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;
|
||||
}
|
||||
|
|
|
@ -71,7 +71,7 @@ public class Scene extends Group {
|
|||
}
|
||||
|
||||
protected void onBackPressed() {
|
||||
Game.instance.finish();
|
||||
Game.quitGame();
|
||||
}
|
||||
|
||||
protected void onMenuPressed() {
|
||||
|
|
|
@ -416,7 +416,7 @@ public class CursedWand {
|
|||
|
||||
@Override
|
||||
protected void onSelect(int index) {
|
||||
Game.instance.finish();
|
||||
ShatteredPixelDungeon.quitGame();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -70,7 +70,7 @@ public class ExitButton extends Button {
|
|||
@Override
|
||||
protected void onClick() {
|
||||
if (Game.scene() instanceof TitleScene) {
|
||||
Game.instance.finish();
|
||||
ShatteredPixelDungeon.quitGame();
|
||||
} else {
|
||||
ShatteredPixelDungeon.switchNoFade( TitleScene.class );
|
||||
}
|
||||
|
|
|
@ -108,7 +108,12 @@ public class WndGame extends Window {
|
|||
new RedButton( Messages.get(this, "exit") ) {
|
||||
@Override
|
||||
protected void onClick() {
|
||||
Game.instance.finish();
|
||||
try {
|
||||
Dungeon.saveAll();
|
||||
} catch (IOException e) {
|
||||
ShatteredPixelDungeon.reportException(e);
|
||||
}
|
||||
ShatteredPixelDungeon.quitGame();
|
||||
}
|
||||
}
|
||||
);
|
||||
|
|
Loading…
Reference in New Issue
Block a user