android - Store async data in recycler view -


i have main activity in have used view pager.so can move between 4 tabs , view pager handles of that.one of tabs scans contacts on phone details , display in recylerview in same tab,this task takes long time , doing in async task.everything working fine problem if move tab while scanning going on data not applied recycler view possible because fragment being destroyed. there workaround or should prevent user shifting tabs while scanning going on (if sort of code or link code helpfull).

i wouldn't recommend force user stay on page whilst data loads. sounds frustrate people. end, have couple of ideas should keep asynctask running whilst fragment isn't visible.

first, call setoffscreenpagelimit(2) on viewpager. have 4 fragments, should mean of them stored in memory.

viewpager.setoffscreenpagelimit(2); 

another approach may able create ui-less fragment sole function conduct asynctask , then, once reaches onpostexecute(), pass cursor result fragment requires either interface or eventbus of sort (i.e. localbroadcastmanager or 1 of other many excellent libraries exist, such greenrobot's eventbus).

edit if information on how create such "worker" fragment, there , detailed post on androiddesignpatterns.


Comments

Popular posts from this blog

resizing Telegram inline keyboard -

command line - How can a Python program background itself? -

php - "cURL error 28: Resolving timed out" on Wordpress on Azure App Service on Linux -