@Override public void onCanceled(SquidCursor<T> data) { if (data != null && !data.isClosed()) { data.close(); } }
@Override public void onCanceled(SquidCursor<T> data) { if (data != null && !data.isClosed()) { data.close(); } }
@Override protected void onReset() { super.onReset(); // Ensure the loader is stopped onStopLoading(); if (cursor != null && !cursor.isClosed()) { cursor.close(); } cursor = null; }
@Override protected void onReset() { super.onReset(); // Ensure the loader is stopped onStopLoading(); if (cursor != null && !cursor.isClosed()) { cursor.close(); } cursor = null; }
@Override public void deliverResult(SquidCursor<T> data) { if (isReset()) { if (data != null) { data.close(); } return; } SquidCursor<T> oldCursor = this.cursor; this.cursor = data; if (isStarted()) { super.deliverResult(data); } if (oldCursor != null && oldCursor != data && !oldCursor.isClosed()) { oldCursor.close(); } }
@Override public void deliverResult(SquidCursor<T> data) { if (isReset()) { if (data != null) { data.close(); } return; } SquidCursor<T> oldCursor = this.cursor; this.cursor = data; if (isStarted()) { super.deliverResult(data); } if (oldCursor != null && oldCursor != data && !oldCursor.isClosed()) { oldCursor.close(); } }
public void testChangeCursorClosesOldCursor() { TestAdapter adapter = new TestAdapter(new TestModel()); SquidCursor<TestModel> cursor1 = database.query(TestModel.class, Query.select()); adapter.swapCursor(cursor1); SquidCursor<TestModel> cursor2 = database.query(TestModel.class, Query.select().where(TestModel.ID.eq(1))); adapter.changeCursor(cursor2); assertTrue(cursor1.isClosed()); adapter.changeCursor(null); cursor2.close(); }
public void testSwapCursorDoesNotCloseOldCursor() { TestAdapter adapter = new TestAdapter(new TestModel()); SquidCursor<TestModel> cursor1 = database.query(TestModel.class, Query.select()); try { adapter.swapCursor(cursor1); SquidCursor<TestModel> cursor2 = database.query(TestModel.class, Query.select().where(TestModel.ID.eq(1))); try { SquidCursor<?> swappedCursor = adapter.swapCursor(cursor2); assertFalse(swappedCursor.isClosed()); } finally { adapter.swapCursor(null); cursor2.close(); } } finally { cursor1.close(); } }