0

I have an Activity A with a RecyclerView in it, and each view in it has a button that opens a new Activity B. When I go back from B to A, RecyclerView will focus on the first view always.

I want to, when return from B to A by backPress, scroll to the selected view position.

2 Answers2

0

you can save the Position of the clicked item and on resume scroll to that position

 int scrollPosition = 0; 
if (linearLayoutManager != null) {
   scrollPosition = inearLayoutManager.findFirstVisibleItemPosition();
}//to get the position

and when restoring use following code

if (linearLayoutManager != null) {
  cardRecyclerView.scrollToPosition(mScrollPosition);
}
0

I believe this is because you are starting activity A with intent.

I recommend you call onBackPressed() when navigating back to activity A instead of starting activity A as a new Intent. If this is the situation.

Anga
  • 2,450
  • 2
  • 24
  • 30