cursor.moveToNext() not working in onLoadFinished after screen rotation

81 views Asked by At

I'm using custom RecyclerView.Adapter to show the list items. I'm using LoaderManager.LoaderCallbacks<Cursor> to fetch the data from the database and in onLoadFinished() I use custom method to extract the data from the cursor and store it in the custom ArrayList one by one using while(cursor.moveToNext()). The list is loaded successfully. But upon screen rotation the list goes off.

When I debugged the code I got to know that the onLoadFinished() is called on screen rotation but the while loop is not working even if the cursor is not null and cursor count is greater than 0.

@Override
public void onLoadFinished(Loader<Cursor> loader, Cursor cursor) {
    loadAndroidFlavours(cursor);

    mCursor = cursor;
    invalidateOptionsMenu();
}

private void loadAndroidFlavours(Cursor cursor) {
    if (cursor.getCount() != 0) {
        while (cursor.moveToNext()) {
            int columnIndexID = cursor.getColumnIndex(AndroidFlavourEntry._ID);
            int columnIndexFlavour = cursor.getColumnIndex(AndroidFlavourEntry.COLUMN_FLAVOUR);
            int columnIndexVersion = cursor.getColumnIndex(AndroidFlavourEntry.COLUMN_VERSION);

            int ID = cursor.getInt(columnIndexID);
            String flavour = cursor.getString(columnIndexFlavour);
            String version = cursor.getString(columnIndexVersion);

            mFavoritesList.add(new AndroidFlavour(ID, flavour, version));
        }
        loadAndroidFlavours();
    } else {
        hideList();
    }
}

I'm stuck. Please help with explanation. Regards!

0

There are 0 answers