Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 17006897 authored by Danny Baumann's avatar Danny Baumann
Browse files

Fix requery behaviour of MemoryCursor.

As we can't restore the contents of the cursor window, we need to keep
it on deactivation so we can restore it on requery().

Change-Id: I06f688bbe9120c307bdc3ddbc3833416becdec82
parent ffda8dd5
Loading
Loading
Loading
Loading
+25 −1
Original line number Diff line number Diff line
@@ -26,7 +26,7 @@ import android.database.DatabaseUtils;
 * @hide
 */
public class MemoryCursor extends AbstractWindowedCursor {

    private CursorWindow mDeactivatedWindow;
    private final String[] mColumnNames;

    public MemoryCursor(String name, String[] columnNames) {
@@ -47,4 +47,28 @@ public class MemoryCursor extends AbstractWindowedCursor {
    public String[] getColumnNames() {
        return mColumnNames;
    }

    @Override
    public boolean requery() {
        if (mDeactivatedWindow != null) {
            setWindow(mDeactivatedWindow);
            mDeactivatedWindow = null;
        }
        return super.requery();
    }

    @Override
    protected void onDeactivateOrClose() {
        // when deactivating the cursor, we need to keep our in-memory cursor
        // window as we have no chance of requerying it later on
        if (!isClosed() && getWindow() != null) {
            mDeactivatedWindow = getWindow();
            mWindow = null;
        }
        super.onDeactivateOrClose();
        if (isClosed() && mDeactivatedWindow != null) {
            mDeactivatedWindow.close();
            mDeactivatedWindow = null;
        }
    }
}