I tried a lot of the possible solutions but they were not useful, simply i don't want to use onBackPressed
to achieve this, i'm trying to get back to the previous Activity
using Intent
, i tried to pass the position with putExtra()
and get position from the intent in the previous Activity and use recycleView.scrollToPosition(pos);
, but the Activity is recreated and the scroll is not working, i also tried to use onSavedInstanceState()
and onRestoreInstanceState
but i got the same results, any one can give me an idea ? thanks in advance.
I also wondering why the method below is not working ?
@Override
protected void onPause() {
super.onPause();
lastFirstVisiblePosition = ((LinearLayoutManager)
recyclerView.getLayoutManager()).findLastVisibleItemPosition();
Log.d("bePos", String.valueOf(lastFirstVisiblePosition));
}
@Override
protected void onResume() {
super.onResume();
Log.d("lastPos", String.valueOf(lastFirstVisiblePosition));
recyclerView.scrollToPosition(lastFirstVisiblePosition);
}
Update
I solved the problem of saving the last position but later i discovered that i can not scroll to that position in RecyclerView
because i'm using pagination, RecyclerView
just can not scroll to an item the adapter does not load yet, so how to solve such an issue ?