refreshing a RecyclerView from onRestoreInstanceState() doesn't work

Viewed 207

I want to restore (into onRestoreInstanceState) some datas, and more precisely an array with local files path. This array is used by my adapter to show images (local):

@Override
    protected void onRestoreInstanceState(Bundle savedInstanceState) {

        ....

        mPicturesList = savedInstanceState.getParcelableArrayList(BUNDLE_KEY_INPUT_FILE_PATH);

        if (mPicturesList != null && mPicturesList.size() > 0) {
            // Refresh list
            mItemPostPictureAdapter.notifyDataSetChanged();
        }             

        super.onRestoreInstanceState(savedInstanceState);
    }

Unfortunately my list is never refresh from here, I don't know why. I put a breakpoint in my adapter, and it's never called here.

In normal process, the refresh list works perfectly, but not from onRestoreInstanceState() function...

1 Answers

Views have their own restoration methods which are called automatically if the views have android:id property set. Lists views (like recycle or listview) can restore their scroll position, but not adapters.

Hence you need to recreate the adapter, fill it with corresponding content and set for your RecyclerView.

Related