giannisj5 giannisj5 - 4 months ago 14
Android Question

SaveInstanceState of RecyclerView

this is my data

List<ItemData> data = new ArrayList<>();

LinearLayoutManager llm = new LinearLayoutManager(this);
MyAdapter mAdapter;
RecyclerView recyclerView;


and this is my recycler view in OnCreate method

recyclerView = (RecyclerView) findViewById(R.id.recycler_view);
recyclerView.setHasFixedSize(true);
recyclerView.setLayoutManager(llm);
llm.setStackFromEnd(true);
mAdapter = new MyAdapter(data, getApplication());
recyclerView.setAdapter(mAdapter);
recyclerView.setItemAnimator(new DefaultItemAnimator());


how can i use onSaveInstanceState and onRestoreInstanceState to save my data list so doesn't dissapear in rotation?

Answer

Not prefered but i used in every activity in my manifest

android:configChanges="orientation|screenSize"
Comments