theblitz
theblitz

Reputation: 6881

Android - What to put in onPause and onSaveInstanceState

I am trying to figure out what should go in onPause and what in onSaveInstanceState.

Taking the example of a card game. I want to restore the hand being played to exactly the same place. Do I do the saving in onPause or onSaveInstanceState?

Upvotes: 1

Views: 1416

Answers (1)

Andrew White
Andrew White

Reputation: 53496

Basic rule to follow - use onSaveInstanceState if you want to put data into a bundle to be by onCreate. Use onPause to write persistent data that can be read during onResume.

In your case you will probably want to put most of your suspend logic in onPause. I find that I almost always use onPause for most suspend logic since my apps (games) don't usually reduce to something that can fit into a bundle easily.

Upvotes: 3

Related Questions