I am trying to save some data in \"MainActivity\" when switching to another activity, and restoring that data as I switch back to it.
In \"MainActivity\": (restoring
You can use onRestoreInstanceState() witch is called after onStart(), whereas onCreate() is called before onStart().
Use the put methods to store values in onSaveInstanceState():
protected void onSaveInstanceState(Bundle bundle) {
super.onSaveInstanceState(bundle);
bundle.putInt("value", value);
}
And restore the value in onCreate():
public void onCreate(Bundle bundle) {
if (bundle!= null){
value = bundle.getInt("value");
}
}