java - RecyclerView with cursor loader is too slow when updating frequently -
i fetching podcast feed db , displaying in recyclerview using loadermanager.loadercallbacks. in content provider:
- i register 'observer' in content resolver query() method with:
cursor.setnotificationuri(getcontext().getcontentresolver(), uri);
- when update/insert/delete in content resolver, notify observer with:
getcontext().getcontentresolver().notifychange(uri, null);
onloaderreset()
triggered when needed
then have service downloadmanager, update progress of ongoing downloads database every second. loader loading data db , can see changing progress of every downloading episode in ui.
i think, wrong approach of notifying change , very slow, can't think of better solution right now. suggest effective solution recyclerview , download progress?
my custom activity recyclerview
public class myactivity implements loadermanager.loadercallbacks<cursor> { private recyclerview mrecyclerview; private mycustomrecyclerviewadapter madapter; ... @override public loader<cursor> oncreateloader(int id, bundle args) { return new cursorloader(this, mydatauri, null, null, null, null ); } @override public void onloadfinished(loader<cursor> loader, cursor data) { madapter.swapcursor(data); } @override public void onloaderreset(loader<cursor> loader) { madapter.swapcursor(null); } ... }
my custom adapter
public class mycustomrecyclerviewadapter extends recyclerview.adapter<episodeadapter.audioadapterviewholder> { ... public void swapcursor(cursor newcursor) { mcursor = newcursor; notifydatasetchanged(); } ... }
reclyclerview
more efficient (specially notifydatasetchanged()
method) when adapter has stable ids.
if data have ids (e.g. db), should consider making adapter use sethasstableids(true) , override getitemid(int position).
i not sure solve problem practice.
Comments
Post a Comment