I've been trying to build a task list in Android, and I want it to remember what is in the list even if the application is closed. I've been trying to do this using onSaveInstanceState
as follows:
public class Main extends Activity implements OnClickListener, OnKeyListener {
...
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
...
if (savedInstanceState != null) {
ToDo = savedInstanceState.getStringArrayList("MyArrayList");
AA.notifyDataSetChanged();
} else {
ToDo = new ArrayList<String>(); // Initiate ToDo
}
}
@Override
public void onSaveInstanceState(Bundle savedInstanceState) {
super.onSaveInstanceState(savedInstanceState);
savedInstanceState.putStringArrayList("MyArrayList", ToDo);
}
// ...To-Do implementation follows
}
But this doesn't work, so I started reading about onSaveInstanceState
and if I understand it right, then you actually cannot save data between sessions with it. So how can you do it then?