I have a question how I can return to the same position of my recyclerView, since when I return from another activity it sends me to the start and I would like to keep the same position in which I left it. It should be noted that I am using a GridLayout and that said recycler is inside a fragment, is it possible to return to the same position as the last view? Thank you.
recyclerView = (RecyclerView) view.findViewById(R.id.recycler);
layoutManager = new GridLayoutManager(getActivity(), 2);
recyclerView.setLayoutManager(layoutManager);
adapter = new Adapter();
recyclerView.setAdapter(adapter);
onPause()
If you load another activity, you can save the position when the initial activity's method executes .Add 2 methods in your adapter, to get and store the position:
to obtain the position you can do it with
.getSelectedPosition()
your Adapter.Upon returning simply move to the position of your adapter.
If you want to preserve the position when your application rotates you can save the position through
onSaveInstanceState()
for example:and inside
onCreate()
retrieve the position:Move your Adapter to the saved position: