java - Close was never specifically called when using ContentProvider -


i having issue android content provider loadermanager. using loadermanager load cursorloader contentprovider , contentprovider calling sqlite class. in sqlite class, calling sql query , returning cursor, not closing cursor or database. understood, that's how supposed work (and doesn't work when close cursor/db), after second visit in activity, getting exception database not being closed. must stupid.

i calling initloader of loadermanager in onactivitycreated of fragment.

here query method in contentprovider:

public synchronized cursor query(final uri uri, final string[] projection, final string selection, final string[] selectionargs, final string sortorder) {     final songdbhandler songdbhandler = abstractactivity.getlocalservice(getcontext()).getdbhandler();     string order = " ";     if ("author".equals(sortorder)) {         order = constants.order_author;     } else if ("song".equals(sortorder)) {         order = constants.order_song;     }     system.out.println("getallsongs");     final cursor cursor = songdbhandler.getallsongs(order);     cursor.setnotificationuri(getcontext().getcontentresolver(), uri);     return cursor; } 

here code in sqlite class (singleton sqliteopenhelper subclass):

public cursor getallsongs(string order) {     sqlitedatabase db = null;     cursor cursor;     try {         db = this.getreadabledatabase();         string sql = "";         sql += "select " + constants.author_select_columns + ", " + constants.song_select_columns + ", " + constants.global_id;         sql += " " + constants.song_table_name + ", " + constants.author_table_name + " ";         sql += " " + constants.song_table_name + "." + constants.author_fk + " = " + constants.author_table_name + "." + constants.author_id + " ,  " + constants.song_table_name + "."                 + constants.song_source_type + " = " + constants.author_table_name + "." + constants.author_source_type;         // sql += " order " + constants.author_table_name + "." +         // constants.author_name + collate;         sql += order;         // sql += " limit 20 ";         cursor = db.rawquery(sql, new string[] {});         return cursor;     } {         //closequietly(db);     } } 

any appreciated!

edit: here loadermanager callback:

@override public loader<cursor> oncreateloader(int loaderid, bundle bundle) {     return (loader<cursor>) new cursorloader(getactivity().getapplicationcontext(), songcontentprovider.getlocalprovideruri(), null, null, null, bundle.getstring("order")); }  @override public void onloadfinished(loader<cursor> arg0, cursor songs) {     updatedata(songs); }  @override public void onloaderreset(loader<cursor> arg0) {     adapter.swapcursor(null); } 

edit2:

private void updatedata(cursor songs) {     adapter.swapcursor(songs);     if (songs == null || songs.getcount() == 0) {         vysledky.setvisibility(view.gone);         vysledkymsg.settext(getstring(r.string.no_results));         vysledkymsg.setvisibility(view.visible);     } else {         vysledky.setvisibility(view.visible);         vysledkymsg.settext(getstring(r.string.progress_loading_content));         vysledkymsg.setvisibility(view.gone);     } } 

after quite time fixed everything. error caused, because db class wasn't singleton , every call created new database connection instance, old reference lost , contentprovder couldn't close it. came this:

  • db class singleton, removed of issues.
  • i closing cursor in onpause , before every restartloader call.

now have 3 concurrent contentloaders in 3 fragments , working fine.


Comments

Popular posts from this blog

php - Submit Form Data without Reloading page -

linux - Rails running on virtual machine in Windows -

php - $params->set Array between square bracket -