1

I know that this question has been resolved in many other threads for example: Saving Android Activity state using Save Instance State I know that the onSaveInstance(Bundle bundle) method is called, but it is always called from the system. I would like to call it when the user presses a button. The only problem as far as I know is that you don't have the reference to the Bundle that is needed to store your bundle. Thanks in advance

Community
  • 1
  • 1
Sanandrea
  • 2,112
  • 1
  • 27
  • 45

1 Answers1

1

Depending on how you need to save your application state, why do you want to use that method and a Bundle? Can you not persist it using SharedPreferences and then load them on resume?

gianpi
  • 3,110
  • 1
  • 17
  • 13
  • 1
    I would like to add a button "Save & Exit" to my game. So the user can choose when to save the state. I practically gave up on doing this and planned to write the bundle created into a file. So I came to this question: http://stackoverflow.com/questions/2598248/how-to-serialize-a-bundle. The user making the question has the same problem. Even there was suggested to use share prefernces as an option. I think it nearly the same effort for me now that Have already implemented createBundle method. – Sanandrea Nov 30 '11 at 17:16
  • The effort might be similar apparently, but with the preferences you have much less to worry about. Depending on what data you're going to save I suggest that you consider using the preferences instead of a file. If it's only a bunch of native types I think it would be a better choice. – gianpi Nov 30 '11 at 17:51
  • Thank you, preferences seems the android way of storing this kind of things. – Sanandrea Dec 01 '11 at 11:54