0

can someone helpme out with how to save state of the app when the screen orientation is changed i read the development guide at http://developer.android.com/guide/topics/resources/runtime-changes.html#HandlingTheChange

but i dont know how to define the method collectMyLoadedData();

can someone help me with an example or something ?

user434885
  • 1,988
  • 6
  • 29
  • 51

2 Answers2

0

The implementation of that function is going to be entirely dependent on the data you are trying to save. You basically just need to create a data structure that contains all of the information you want to be saved, and return that from onRetainNonConfigurationInstance.

Sketchy example: Your page has a person entering a name and address.

public class LoadedData {
   private String name;
   private Adddress address;
   ...
}

public LoadedData collectMyLoadedData() {
  LoadedData data = new LoadedDate();
  data.setName(myNameTextBox.getText());
  ....
  return data;
}
Cheryl Simon
  • 46,552
  • 15
  • 93
  • 82
0

thank you... also found another example

Saving Android Activity state using Save Instance State

Community
  • 1
  • 1
user434885
  • 1,988
  • 6
  • 29
  • 51
  • 1
    The timing and method for saving state described there is different from the one you mention in your question. onRetainNonConfigurationInstance is designed to save large amounts of state only on a configuration change like screen orientation. saveInstanceState is used more generally when the activity lifecycle causes the activity to be killed and restarted. – Cheryl Simon Sep 01 '10 at 19:14
  • Also, on StackOverflow if an answer helps you, you should upvote it or mark it as the correct answer by clicking the check box to the left of the answer. – Cheryl Simon Sep 01 '10 at 19:15