Wednesday, 15 August 2012

Android SQLite callback after transaction is complete -



Android SQLite callback after transaction is complete -

looking solution sqlite error i'm encountering in android. in cases i'm running insert query, closing activity i'm in , moving next. closing activity entails making sure sqlitedatabase stopped, onpause in activity stops database.

however i'm struggling create app wait until transaction done. see there exists sqlitetransactionlistener, oncommit method called before commit, leaving open possibility in mind in cases end same problem.

how can callback when transactions closed can delay shutting downwards database object?

public void insertarraylist(sqlitedatabase db, string table, arraylist<arraylist<string>> tabledata, boolean clear) { logg.d("start"); cursor cols = db.rawquery("select * " + table + " limit 0",null); db.begintransaction(); seek { if (clear) {db.execsql("delete " + table);} int xtra = cols.getcolumncount() - tabledata.get(0).size(); (arraylist<string> item : tabledata) { (int a=0;a<xtra;a++) {item.add("");} db.execsql("insert " + table + " values " + rowvalues(item) + ";"); //logg.i("insert " + table + " values " + rowvalues(item) + ";"); } db.settransactionsuccessful(); } grab (exception e) { logg.e("error: " + e.getmessage()); } { db.endtransaction(); logg.d("finish"); } }

activity onpause override:

@override public void onpause() { if (db != null) { logg.d("sqlite db closing"); db.close(); } super.onpause(); }

don´t stop database! utilize same database stored in custom application class. it´s open long application open , close onterminate().

android sqlite callback listener

No comments:

Post a Comment