How to open sqlite DB in onrestart()

I am updating home listview using data retrieved from DB. When I go forth then comeback to Home it crashes

My code is here

protected void onRestart() {
    super.onRestart();
    Log.i(TAG, "onRestart called");
    DatabaseManager.getInstance(HomeActvity.this).open();
    listAdapter.notifyDataSetChanged();
    DatabaseManager.getInstance(HomeActvity.this).closeDatabase();
}

My Log is:

11-28 19:07:22.606: E/AndroidRuntime(24303): java.lang.IllegalStateException: database not open
11-28 19:07:22.606: E/AndroidRuntime(24303):    at android.database.sqlite.SQLiteDatabase.queryWithFactory(SQLiteDatabase.java:1224)
11-28 19:07:22.606: E/AndroidRuntime(24303):    at android.database.sqlite.SQLiteDatabase.query(SQLiteDatabase.java:1184)
11-28 19:07:22.606: E/AndroidRuntime(24303):    at android.database.sqlite.SQLiteDatabase.query(SQLiteDatabase.java:1264)

I tried runOnUIThread()..

Answers


Why do you close your database right after notifydatachanged? I think database reading is happening after close. Try to remove the line and see if it's working.

DatabaseManager.getInstance(HomeActvity.this).open();
listAdapter.notifyDataSetChanged();

DatabaseManager.getInstance(HomeActvity.this).closeDatabase();


You are doing nothing in between open and close! how come..


Need Your Help

How to get the date/time at which an image was taken using CCR EXIF?

delphi exif

using CCR EXIF http://delphihaven.wordpress.com/ccr-exif/ how can I get the time at which an image was taken?

PHP+Ajax : Add-a-friend system

php mysql ajax mysqli friend

I'm trying to make a little project for adding friends.