Search code examples
androidsqlbrite

Does SQLBrite close cursor automatically?


I have the doubt to wether sqlbrite close cursor automatically, it seems that it doesn't do it since I keep getting :

java.lang.Throwable: Explicit termination method 'close' not called at dalvik.system.CloseGuard.open(CloseGuard.java:180) at android.database.sqlite.SQLiteDatabase.openInner(SQLiteDatabase.java:809) at android.database.sqlite.SQLiteDatabase.open(SQLiteDatabase.java:793)

but I don't see anything in docs stating that I should be explicitly call cursor.close.

Edit 1

Here is a snippet of what is giving me a cursor not close error:

DbProvider.db(getActivity()).createQuery(Item.NAME, sqlQuery, selectionArgs).mapToList(new Func1<Cursor, ItemEntity>() {
    @Override
    public ItemEntity call(Cursor cursor) {
        return new ItemEntity(cursor);
    }
}).subscribe(itemEntities -> {
    Debug.info(this, "items " + itemEntities );
}, Throwable::printStackTrace, () -> {});

Solution

  • if you are calling query.run() and getting a cursor you need to close it manually. If you are using the mapToList/mapToOne api's you do not need to close it manually.