android - Using pagination with CursorLoader and MergeCursor closes old cursors -


as title says, when trying paginate listview backed simplecursoradapter , cursorloader, old cursors getting closed, below exception being thrown. first 2 pages load fine (the first isn't using mergecursor , second page first 1 use mergecursor). don't call close() on cursor whatsoever.

what interesting while debugging, cannot see closed flags on cursor being set true, it's worth. might issue mergecursor then. let me know if guys have solutions, i'm out of ideas.

stack trace:

android.database.staledataexception: attempting access closed cursorwindow.most probable cause: cursor deactivated prior calling method.     @ android.database.abstractwindowedcursor.checkposition(abstractwindowedcursor.java:139)     @ android.database.abstractwindowedcursor.getlong(abstractwindowedcursor.java:74) 

code:

private list<cursor> mcursorslist = new arraylist<>();  @override public void onscroll(abslistview view, int firstvisibleitem,                      int visibleitemcount, int totalitemcount) {     if (!isloading && !isallloaded &&             firstvisibleitem != 0 &&             firstvisibleitem == totalitemcount - visibleitemcount)         getactivity().getsupportloadermanager().restartloader(loader_id, null, this); }  @override public void onloadfinished(loader<cursor> loader, final cursor data) {         cursor oldcursor = mcursoradapter.getcursor();         mcursorslist.add(data);         if (oldcursor != null)         {             cursor[] cursorarray = mcursorslist.toarray(new cursor[mcursorslist.size()]);             mergecursor newcursor = new mergecursor(cursorarray);             mcursoradapter.swapcursor(newcursor);         }         else // first cursor         {             mcursoradapter.swapcursor(data);         } }  @override public void onloaderreset(loader<cursor> loader) { } 

the main cause of issue cursorloader manages inner cursor, whenever needs open new 1 (such new page query), closes old cursor.

for more simple pagination implementation, don't query offsets, bump limit on every page, new cursor contains previous pages well. also, ian lake suggested on google+, don't need pagination, if doing complicated joins or sorting data.


Comments

Popular posts from this blog

c++ - llvm function pass ReplaceInstWithInst malloc -

Cross-Compiling Linux Kernel for Raspberry Pi - ${CCPREFIX}gcc -v does not work -

java.lang.NoClassDefFoundError When Creating New Android Project -