android - Should I use a Cursor or a CursorLoader? -
i have android app in have login system , other stuff communicate server. web server confirmation , lot of data. far using simple database. today implemented content provider working far. data contentprovider used cursor cursor = getcontentresolver().query();
, saw there option use cursorloader. difference between them ? in case should use ? saw have implement in every class cursorloader, can't make single class , call when it's needed ?
as documentation states,
cursorloader implements loader protocol in standard way querying cursors, building on asynctaskloader perform cursor query on background thread not block application's ui.
this biggest advantage of using loaders, i.e. asynchronous. of other important advantages mentioned here.
- they provide asynchronous loading of data.
- they monitor source of data , deliver new results when content changes.
- they automatically reconnect last loader's cursor when being recreated after configuration change. thus, don't need re-query data.
if use default cursors querying content provider directly need handle closing them, , said have huge data, you'd have run query code on different thread. these purposes using cursorloaders simpler , efficient. code on how use one, check this out.
as second question,
i saw have implement in every class cursorloader, can't make single class , call when it's needed ?
you can make base class implementing loader callbacks , can inherit base class classes need use cursorloaders.
Comments
Post a Comment