I started studying Android and I ended up falling into this problem.
I created a RecyclerView
where it is fed by a TextView
field, but every time I rotate the simulator, the values are zeroed.
I found some questions in the English StackOverflow but I can not reproduce the same results in my test app.
I tried to use the following methods, but it does not work.
@Override
public void onSaveInstanceState(Bundle outState, PersistableBundle outPersistentState) {
super.onSaveInstanceState(outState, outPersistentState);
outState.putStringArrayList("myDataSet", myDataSet);
}
@Override
protected void onRestoreInstanceState(Bundle savedInstanceState) {
super.onRestoreInstanceState(savedInstanceState);
}
And when I try to get the onCreate()
it ends up crashing the app, saying List<>
can not be null
private ArrayList<String> myDataSet = new ArrayList<String>();
Part I call no onCreate()
if(savedInstanceState != null){
ArrayList<String> savedMyDataSet = savedInstanceState.getStringArrayList("myDataSet");
myDataSet = savedMyDataSet;
}