0

I've got a simple native application for debugging,
only displaying a triangle slowly changing the color.

Now, when i press the home-button and put my app into background
and then start it again, it is completely restarted.
How can i resume the old state?

I already tried to do it like in the native-app-example with:

app->userdata = &my_state;

if (app->savedState != NULL)
    my_state = *(State*)app->savedState;

and in handle_cmd with:

    case APP_CMD_SAVE_STATE:
        app->savedState = malloc(sizeof(State));
        *((State*)app->savedState) = my_state;
        app->savedStateSize = sizeof(State);
        break;

where State is class with all things i want to save.
How could i do this?

alex
  • 10,900
  • 15
  • 70
  • 100
bricklore
  • 4,125
  • 1
  • 34
  • 62

1 Answers1

0

Isn't necessary to be a class. It could be a struct (that in fact is the "same"). You have to have all your values that you'll need to restore the state of the app in that struct or class, and read from that place.

Reading some examples, you'll see that it's normal to put an engine in the app userData like:

app->userData = &engine;

and in that engine, to have the struct from State. From that way, you could save only what you need, and leave the other.

The important thing is to use always the values (like the colour of the triangle) from that save state, and restore with that code you write.

PD: For more complex things, when you use dynamic memory, you'll have to be more subtle saving data.

jcoll
  • 740
  • 9
  • 10