3
I started to study Android and I ended up falling into this problem.
I created a RecyclerView
where it is fed by a field TextView
, but every time I rotate the simulator, the values are reset.
I found some questions in Stackoverflow English but could not reproduce the same results in my test app.
I tried using the following methods, but it doesn’t 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 hold onCreate()
ends up crashing the app, saying that the List<>
cannot be null
private ArrayList<String> myDataSet = new ArrayList<String>();
Part I call in the onCreate()
if(savedInstanceState != null){
ArrayList<String> savedMyDataSet = savedInstanceState.getStringArrayList("myDataSet");
myDataSet = savedMyDataSet;
}