It happens because of the:
db.close();
in the methods:
void addContact(Contact contact)
public void deleteContact(Contact contact)
You should not close the connection to the underlying database unless you really do not intend to work with it anymore.
Use SQLiteOpenHelper:close
, when you’ve finished your work.
Moreover, calls to getReadableDatabase()
and getWriteableDatabase()
return the same database object 99% of a time, and they do not reinitialize database connection closed manually by you.
Don’t get fooled by these method names.