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.setRenderer( this );
|
||||||
view.setOnTouchListener( this );
|
view.setOnTouchListener( this );
|
||||||
setContentView( view );
|
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
|
@Override
|
||||||
public void onStart() {
|
public void onStart() {
|
||||||
super.onStart();
|
super.onStart();
|
||||||
|
|
||||||
now = 0;
|
if (Build.VERSION.SDK_INT > Build.VERSION_CODES.GINGERBREAD_MR1){
|
||||||
paused = false;
|
resumeGame();
|
||||||
view.onResume();
|
}
|
||||||
|
|
||||||
Music.INSTANCE.resume();
|
|
||||||
Sample.INSTANCE.resume();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onStop() {
|
public void onStop() {
|
||||||
super.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) {
|
if (scene != null) {
|
||||||
scene.pause();
|
scene.pause();
|
||||||
}
|
}
|
||||||
|
@ -174,6 +202,22 @@ public class Game extends Activity implements GLSurfaceView.Renderer, View.OnTou
|
||||||
Sample.INSTANCE.pause();
|
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(){
|
public boolean isPaused(){
|
||||||
return paused;
|
return paused;
|
||||||
}
|
}
|
||||||
|
|
|
@ -71,7 +71,7 @@ public class Scene extends Group {
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void onBackPressed() {
|
protected void onBackPressed() {
|
||||||
Game.instance.finish();
|
Game.quitGame();
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void onMenuPressed() {
|
protected void onMenuPressed() {
|
||||||
|
|
|
@ -416,7 +416,7 @@ public class CursedWand {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onSelect(int index) {
|
protected void onSelect(int index) {
|
||||||
Game.instance.finish();
|
ShatteredPixelDungeon.quitGame();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -70,7 +70,7 @@ public class ExitButton extends Button {
|
||||||
@Override
|
@Override
|
||||||
protected void onClick() {
|
protected void onClick() {
|
||||||
if (Game.scene() instanceof TitleScene) {
|
if (Game.scene() instanceof TitleScene) {
|
||||||
Game.instance.finish();
|
ShatteredPixelDungeon.quitGame();
|
||||||
} else {
|
} else {
|
||||||
ShatteredPixelDungeon.switchNoFade( TitleScene.class );
|
ShatteredPixelDungeon.switchNoFade( TitleScene.class );
|
||||||
}
|
}
|
||||||
|
|
|
@ -108,7 +108,12 @@ public class WndGame extends Window {
|
||||||
new RedButton( Messages.get(this, "exit") ) {
|
new RedButton( Messages.get(this, "exit") ) {
|
||||||
@Override
|
@Override
|
||||||
protected void onClick() {
|
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