I've have an interface that allows me to switch between different scenes in my Android game. When the home key is pressed, I am saving all of my states (score, sprite positions etc) into a Bundle. When re-launching, I am restoring all my states and all is OK - however, I can't figure out how to save my 'Scene', thus when I return, it always starts at the default screen which is the 'Main Menu'.

How would I go about saving my 'Scene' (into a Bundle)?


import android.view.MotionEvent;

public interface Scene{

void render();
void updateLogic();
boolean onTouchEvent(MotionEvent event);


I assume the interface is the relevant piece of code which is why I've posted that snippet.

I set my scene like so: ('options' is an object of my Options class which extends MainMenu (Another custom class) which, in turn implements the interface 'Scene')

 SceneManager.getInstance().setCurrentScene(options);  //Current scene is optionscreen

1 Answer 1


Use a piece of data to denote your scenes. A simple enumeration is the easy way; even a string works just fine in a pinch.

Your interface should be extended to have something like

ESceneType getSceneType();

which returns the type of that scene (e.g. ESceneType.MainMenu or ESceneType.Pause or whatever).

You then create a factory object which, using either a data set or a hard-coded switch statement or the like, instantiates scene objects based on id. The low-tech hard-coded version is something like

Scene createScene(ESceneType type) {
  switch (type) {
    case ESceneType.MainMenu: return new SceneMainMenu();
    case ESceneType.Pause: return new ScenePause();
    case ESceneType.Play: return new ScenePlay();
    default: throw error;

Now you can save this scene type value easily, query it from the active Screne instance, and recreate a scene from it.

  • \$\begingroup\$ Hi @SeanMiddleditch - thanks for this, I don't quite understand how this works, what exacly is ESceneType? I can currently get my scene type by doing the following: SceneManager.getInstance().getCurrentScene(); I'm don't quite understand how this can be used to save / recall the Scene - could you elaborate please? Thanks! \$\endgroup\$ Jun 26, 2013 at 17:51
  • \$\begingroup\$ "a simple enumeration" - just make an easy to serialize piece of data to identify your scenes and then reconstruct them when loading. I'm assuming your getCurrentScene return an instance of a Scene derived type, not an identifier for the scene. You have to make your own enumeration or string types here, or utilize Java's introspection APIs. If you need any extra per-scene data you'll need to serialize that yourself, too. How to do that is more of a basic programming/Java query not specific to game development. \$\endgroup\$ Jun 26, 2013 at 18:00
  • \$\begingroup\$ I actually went for a similar but simpler form of this in the end, I held an simple int value and changed it when I changed the scene, then just saved that to / restored from the Bundle and switched it to set the current scene - simple :-) \$\endgroup\$ Sep 19, 2014 at 18:10

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .