How to save scroll position of RecyclerView in Android?

I have Recycler view which lays inside of SwipeRefreshLayout. Also, have ability to open each item in another activity.
After returning back to Recycler I need scroll to chosen item, or to previous Y.
How to do that?

Yes, I googled, found articles in StackOverFlow about saving instance of layout manager, like this one: RecyclerView store / restore state between activities.
But, it doesn’t help me.

  • Android - How to programmatically change timepicker mode?
  • ListViews - how to use ArrayAdapter.addAll() function before API 11?
  • Can't resize a RelativeLayout inside a ScrollView to fill the whole screen
  • Xml namespace declaration: auto-substitute package name
  • SSL/TLS protocols and cipher suites with the AndroidHttpClient
  • Android data-binding (similar to WPF)?

    Right now I have this kind of resolving problem, but, of course, it also doesn’t work.

    private int scrollPosition;
    ...//onViewCreated - it is fragment
    LinearLayoutManager llm = new LinearLayoutManager(getActivity());
    data = new ArrayList<>();
    adapter.setData(getActivity(), data);
    public void onResume() {
    public void onPause() {
        scrollPosition = recyclerView.getScrollY();

    Yes, I have tried scrollTo(int, int) – doen’t work.

    Now I tried just scroll, for example, to Y = 100, but it doesn’t scrolling at all.

    Related posts:

    How to know whether I am in a call on Android?
    Saving user information in app settings
    Android : Floating Clickable Icon over Screen?
    Android private content provider?
    Turning on screen programmatically
    Note: can&#039;t find dynamically referenced class libcore...
  • android button selector
  • app-release-unsigned.apk is not signed
  • android : set textView style at runtime
  • which would be the best to do make a horizontal scrolling app in android?
  • How to create RecyclerView with multiple view type?
  • How to remove a runnable from a handler object added by postDelayed?
  • 4 Solutions collect form web for “How to save scroll position of RecyclerView in Android?”

    Save the current state of recycle view position @onPause:

        positionIndex= llManager.findFirstVisibleItemPosition();
        View startView = rv.getChildAt(0);
        topView = (startView == null) ? 0 : (startView.getTop() - rv.getPaddingTop());

    Restore the scroll position @onResume:

        if (positionIndex!= -1) {
            llManager.scrollToPositionWithOffset(positionIndex, topView);

    or another way can be @onPause:

    long currentVisiblePosition = 0;
    currentVisiblePosition = ((LinearLayoutManager)rv.getLayoutManager()).findFirstCompletelyVisibleItemPosition();

    restore @onResume:

    ((LinearLayoutManager) rv.getLayoutManager()).scrollToPosition(currentVisiblePosition);
    currentVisiblePosition = 0;

    User your recycler view linearlayoutmanager for getting scroll position

    int position = 0;
    if (linearLayoutManager != null) {
       scrollPosition = inearLayoutManager.findFirstVisibleItemPosition();

    and when restoring use following code

    if (linearLayoutManager != null) {

    Hope this helps you

    You can use scrollToPosition or smoothScrollToPosition to scroll to any item position in RecyclerView.

    If you want to scroll to item position in adapter, then you would have to use adapter’s scrollToPosition or smoothScrollToPosition.

    A lot of these answers seem to be over complicating it.

    The LayoutManager supports onRestoreInstanceState out of the box so there is no need to save scroll positions etc. The built in method already saves pixel perfect positions.

    example fragment code (null checking etc removed for clarity):

    private Parcelable listState;
    private RecyclerView list;
    public void onCreate(@Nullable Bundle savedInstanceState) {
    public void onSaveInstanceState(Bundle outState) {
        outState.putParcelable("ListState", list.getLayoutManager().onSaveInstanceState());

    then just call


    once your data has been reattached to your RecyclerView

    Android Babe is a Google Android Fan, All about Android Phones, Android Wear, Android Dev and Android Games Apps and so on.