tags:

views:

35

answers:

2

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 ?

A: 

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;
}
Mayra
A: 

thank you... also found another example

http://stackoverflow.com/questions/151777/how-do-i-save-an-android-applications-state

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.
Mayra
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.
Mayra