lundi 23 février 2015

Android - SQLite db keeps showing rows that should have been deleted

I'm currently creating an app that downloads lists from a server and places those lists into an SQLite database. In the Mainactivity it calls the lists from the db and places them into a custom adapter, everything works fine and such.


After this I go through several screens to proces the listdata and in the final activity it uses a query to delete the row it's been working on from the db. I use logcat to print the db after this and it shows that the row has been deleted.


Next it takes me back to the Mainactivity and in its onResume I once again load the lists from the db only to find that the row that should have been deleted is still in it.


Mainactivity:



private List<String> list = new ArrayList<>();

public void onResume() {
super.onResume();
context = getApplicationContext();

ConsLoadListDataSource cllDataSource = new ConsLoadListDataSource(context);
cllDataSource.open();
list = cllDataSource.sqliteToListIds();
cllDataSource.close();

logcat("Jadajada: " + list.toString());

}


SQLiteHelper:



public List<String> sqliteToListIds() {
List<String> conList= new ArrayList<>();

if (!db.isOpen()) {
open();
}
Cursor cursor = db.query(ConsLoadListSQLHelper.TABLE_CONS_HEADER,
allConsListColumns, null, null, "loadlist" , null, "loadlist");
cursor.moveToFirst();

while (!cursor.isAfterLast()) {
conList.add(cursor.getString(1));
cursor.moveToNext();
}
db.close();

return conList;
}

Aucun commentaire:

Enregistrer un commentaire