scroll to last position of recyclerview
<p>I want to scroll to last saved position of recyclerview after destroying or pausing app. I have used below code for saving related position and offset in <code>SharedPreferences</code></p>

<pre><code>@Override
public void onPause() {
    super.onPause();
    QueryPreferences.setLastPos(getActivity(), String.valueOf(((LinearLayoutManager) mRecyclerView.getLayoutManager()).findFirstVisibleItemPosition()));
    QueryPreferences.setLastOffset(getActivity(), String.valueOf(mRecyclerView.computeVerticalScrollOffset()));
}
</code></pre>

<p>and below code for getting position and offset and then scrolling to last position of recyclerview:</p>

<pre><code>@Override
public void onResume() {
    super.onResume();
    updateUI();//initialization of recyclerview and adapter
    //final int scrllPosition=Integer.parseInt(QueryPreferences.getLastPos(getActivity()));
    final int scrllOffset=Integer.parseInt(QueryPreferences.getLastOffset(getActivity()));
    mLayoutManager.scrollToPositionWithOffset(0,-scrllOffset);//scrolling down
    //I also tried mRecyclerView.scrollBy(0, scrllOffset);
}
</code></pre>

<p>if I set offset equal to zero, scrolling is done without any problem (scrolls to top of an item), but when I set an offset, recyclerview scrolls to another item (not last saved item position) even with applying delay using <code>Handler().postDelayed</code>. I should note that using <code>computeVerticalScrollOffset()</code>, I got offsets as large as 73000 which implies that this offset is relative to first item (position 0). How can I correctly get the offset and scroll to desired item with correct offset? Thank You in Advance.</p>