-
Notifications
You must be signed in to change notification settings - Fork 35
Description
First off, I love your work.
Calls to the ORM seems to behave reliably even when initiated from multiple threads. However I'm experiencing issues using Androrm's DatabaseAdapter with a ContentProvider.
An example:
public class OWContentProvider extends ContentProvider {
public Cursor query(Uri uri, String[] projection, String selection,
String[] selectionArgs, String sortOrder) {
DatabaseAdapter adapter = DatabaseAdapter.getInstance(getContext().getApplicationContext());
...
Cursor result = adapter.open().query(SQLString);
adapter.close(); // I've tried removing this line and modifying DatabaseAdapter to never close it's connection
return
}
}
Within a few requests this will inevitably produce a java.lang.IllegalStateException: attempt to re-open an already-closed object
or a android.database.StaleDataException: Attempting to access a closed CursorWindow.Most probable cause: cursor is deactivated prior to calling this method.
. If I call adapter.close()
before returning I'll get the IllegalStateException pretty reliably.
Is there a preferred way to safely get a Cursor via androrm?
Example java.lang.IllegalStateException trace. The ContentProvider calls are coming from a Loader which is controlled by a AutoCompleteTextView.
12-23 01:17:11.155: E/AndroidRuntime(11696): java.lang.IllegalStateException: attempt to re-open an already-closed object: SQLiteQuery: SELECT _id, name FROM owrecordingtag where name LIKE "%p%" 12-23 01:17:11.155: E/AndroidRuntime(11696): at android.database.sqlite.SQLiteClosable.acquireReference(SQLiteClosable.java:55) 12-23 01:17:11.155: E/AndroidRuntime(11696): at android.database.sqlite.SQLiteQuery.fillWindow(SQLiteQuery.java:58) 12-23 01:17:11.155: E/AndroidRuntime(11696): at android.database.sqlite.SQLiteCursor.fillWindow(SQLiteCursor.java:151) 12-23 01:17:11.155: E/AndroidRuntime(11696): at android.database.sqlite.SQLiteCursor.onMove(SQLiteCursor.java:124) 12-23 01:17:11.155: E/AndroidRuntime(11696): at android.database.AbstractCursor.moveToPosition(AbstractCursor.java:214) 12-23 01:17:11.155: E/AndroidRuntime(11696): at android.database.CursorWrapper.moveToPosition(CursorWrapper.java:162) 12-23 01:17:11.155: E/AndroidRuntime(11696): at android.support.v4.widget.CursorAdapter.getItem(CursorAdapter.java:213) 12-23 01:17:11.155: E/AndroidRuntime(11696): at android.widget.AutoCompleteTextView.buildImeCompletions(AutoCompleteTextView.java:1122) 12-23 01:17:11.155: E/AndroidRuntime(11696): at android.widget.AutoCompleteTextView.showDropDown(AutoCompleteTextView.java:1082) 12-23 01:17:11.155: E/AndroidRuntime(11696): at android.widget.AutoCompleteTextView.updateDropDownForFilter(AutoCompleteTextView.java:971) 12-23 01:17:11.155: E/AndroidRuntime(11696): at android.widget.AutoCompleteTextView.onFilterComplete(AutoCompleteTextView.java:953) 12-23 01:17:11.155: E/AndroidRuntime(11696): at android.widget.Filter$ResultsHandler.handleMessage(Filter.java:285) 12-23 01:17:11.155: E/AndroidRuntime(11696): at android.os.Handler.dispatchMessage(Handler.java:99) 12-23 01:17:11.155: E/AndroidRuntime(11696): at android.os.Looper.loop(Looper.java:137) 12-23 01:17:11.155: E/AndroidRuntime(11696): at android.app.ActivityThread.main(ActivityThread.java:5039) 12-23 01:17:11.155: E/AndroidRuntime(11696): at java.lang.reflect.Method.invokeNative(Native Method) 12-23 01:17:11.155: E/AndroidRuntime(11696): at java.lang.reflect.Method.invoke(Method.java:511) 12-23 01:17:11.155: E/AndroidRuntime(11696): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793) 12-23 01:17:11.155: E/AndroidRuntime(11696): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560) 12-23 01:17:11.155: E/AndroidRuntime(11696): at dalvik.system.NativeStart.main(Native Method)