I have a helper database object. It is important that I close it, leaving the activity, so I do it. However, when I return to activity, I get a warning about a database request that is already closed. The query does work, but still something is clearly wrong.
My understanding of the Android activity life cycle is not strong, but I would suggest that I need to open the database again in onResume (). This is not true?
Here onResume ():
@Override
protected void onResume() {
super.onResume();
dbHelper.setInteger(playerID);
dbHelper.openDataBase();
ourCursor = dbHelper.getPlayerSavedQuestions();
startManagingCursor(ourCursor);
adapter = new MyCustomAdapter(ourCursor);
myListView.setAdapter(adapter);
}
Here is dbHelper.openDataBase ();
public void openDataBase() throws SQLException {
String myPath = DATABASE_PATH + DATABASE_NAME;
dbSqlite = SQLiteDatabase.openDatabase(myPath, null,
SQLiteDatabase.OPEN_READWRITE);
}
Here is my logcat:
06-15 13:51:32.388: W/SQLiteCursor(26750): requery() failed database /data/data/com.boboshi.exquizit.eng/databases/exquizit_custom.mp3 (conn
06-15 13:51:32.388: W/SQLiteCursor(26750): java.lang.IllegalStateException: database /data/data/com.boboshi.exquizit.eng/databases/exquizit_custom.mp3 (conn
06-15 13:51:32.388: W/SQLiteCursor(26750): at android.database.sqlite.SQLiteDatabase.verifyDbIsOpen(SQLiteDatabase.java:2082)
06-15 13:51:32.388: W/SQLiteCursor(26750): at android.database.sqlite.SQLiteDatabase.getDbConnection(SQLiteDatabase.java:2407)
06-15 13:51:32.388: W/SQLiteCursor(26750): at android.database.sqlite.SQLiteDatabase.getDatabaseHandle(SQLiteDatabase.java:2388)
06-15 13:51:32.388: W/SQLiteCursor(26750): at android.database.sqlite.SQLiteCursor.requery(SQLiteCursor.java:246)
06-15 13:51:32.388: W/SQLiteCursor(26750): at android.app.Activity.performRestart(Activity.java:4505)
06-15 13:51:32.388: W/SQLiteCursor(26750): at android.app.Activity.performResume(Activity.java:4531)
06-15 13:51:32.388: W/SQLiteCursor(26750): at android.app.ActivityThread.performResumeActivity(ActivityThread.java:2434)
06-15 13:51:32.388: W/SQLiteCursor(26750): at android.app.ActivityThread.handleResumeActivity(ActivityThread.java:2472)
06-15 13:51:32.388: W/SQLiteCursor(26750): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1173)
06-15 13:51:32.388: W/SQLiteCursor(26750): at android.os.Handler.dispatchMessage(Handler.java:99)
06-15 13:51:32.388: W/SQLiteCursor(26750): at android.os.Looper.loop(Looper.java:137)
06-15 13:51:32.388: W/SQLiteCursor(26750): at android.app.ActivityThread.main(ActivityThread.java:4424)
06-15 13:51:32.388: W/SQLiteCursor(26750): at java.lang.reflect.Method.invokeNative(Native Method)
06-15 13:51:32.388: W/SQLiteCursor(26750): at java.lang.reflect.Method.invoke(Method.java:511)
06-15 13:51:32.388: W/SQLiteCursor(26750): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
06-15 13:51:32.388: W/SQLiteCursor(26750): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
06-15 13:51:32.388: W/SQLiteCursor(26750): at dalvik.system.NativeStart.main(Native Method)
source
share