findFirstVisibleItemPosition() of the recyclerview always returns -1
<p>This is the code in which I want to retain recyclerview's scrolled position on orientation change and on activity resume. The problem is in my log, I always get -1. Where am I going wrong?</p>

<pre><code>void resetViews() {
    recyclerView.setAdapter(adapter);
    recyclerView.setLayoutManager(new LinearLayoutManager(getApplicationContext()));
    RecyclerView.LayoutManager lm =  recyclerView.getLayoutManager();
    if (lm != null &amp;&amp; lm instanceof  LinearLayoutManager) {
        currPosition = ((LinearLayoutManager)lm).findFirstVisibleItemPosition();
        Log.i("saz","curr pos : " + currPosition);
    }
    int count = lm.getChildCount();
    if (currPosition != RecyclerView.NO_POSITION &amp;&amp; currPosition &lt; count){
        lm.scrollToPosition(currPosition);
    }
}
</code></pre>