I have an application with checkboxes, How can i save them?
My layout is:
Override onSaveInstanceState(Bundle outState) and write which ones are checked into outState. Then you can see which ones are checked when the activity is create by extracting that information from savedInstanceState passed to onCreate(Bundle savedInstanceState)
For example,
@Override
protected void onSaveInstanceStat(Bundle b){
b.putBoolean("een",een.isChecked());
b.putBoolean("v52",v52.isChecked());
b.putBoolean("v53",v53.isChecked());
// ... etc
}
@Override
protected void onCreate (Bundle savedInstanceState){
// everything you have in your onCreate implementation
een.setChecked(b.getBoolean("een"));
v52.setChecked(b.getBoolean("v52"));
v53.setChecked(b.getBoolean("v53"));
// ... etc
}
IMPORTANT: There is no guarantee that 'onSaveInstanceState' will be called. So only use this if saving the ui state is for convenience for the user and not vital to functionality. User will be happier if you don't save data on their device, ie by using SharedPreference.