Resetting or refreshing a database connection

Posted by cdonner on Stack Overflow See other posts from Stack Overflow or by cdonner
Published on 2010-06-13T18:54:16Z Indexed on 2010/06/13 19:02 UTC
Read the original article Hit count: 442

This Android application on Google uses the following method to refresh the database after replacing the database file with a backup:

public void resetDbConnection() { 
    this.cleanup(); 
    this.db = 
        SQLiteDatabase.openDatabase(
           "/data/data/com.totsp.bookworm/databases/bookworm.db",
            null, SQLiteDatabase.OPEN_READWRITE); 
} 

I did not build this app, and I am not sure what happens. I am trying to make this idea work in my own application, but the data appears to be cached by the views, and the app continues to show data from the database that was replaced, even after I call cleanup() and reopen the database. I have to terminate and restart the activity in order to see the new data.

I tried to call invalidate on my TabHost view, which pretty much contains everything. I thought that the views would redraw and refresh their underlying data, but this did also not have the expected result.

I ended up restarting the activity programmatically, which works, but this seems to be a drastic measure. Is there a better way?

© Stack Overflow or respective owner

Related posts about android

Related posts about sqlite