awareeye
awareeye

Reputation: 3061

How to pause and resume android game?

I am making an android game called Connect4. I am facing a problem relating to pausing and resuming the game. When i run the game on a real device(on a Galaxy S2), while running the game, when i press the power button, the screen gets locked, and when i unlock the screen, my game does not resume from where i left it. Basically, i need 3 things to resume my game, a byte array, a byte, and a FrameLayout object. Here is the code I am using:-

......
public void onSaveInstanceState(Bundle out){
    super.onSaveInstanceState(out);
    out.putParcelable("save", new Save());
}
public class Save implements Parcelable {

byte discs1, disc1[][];
FrameLayout root1;

Save(byte discs, byte[][] disc, FrameLayout root){
    discs1=discs;
    disc1=disc;
    root1=root;

}

Then in the onCreate() i restore them using the supplied bundle, but this not seem to work.

Upvotes: 2

Views: 4351

Answers (2)

Raul Rodrigues
Raul Rodrigues

Reputation: 3

You should use the onRestart() function.

Upvotes: 0

fredley
fredley

Reputation: 33901

Have a look at the Activity Lifecycle. You'll need to overwrite onPause(), onResume() etc. with code to save and restore your game when your app loses focus.

Upvotes: 3

Related Questions