Note that there are some explanatory texts on larger screens.

plurals
  1. POSoftware pattern to use to load data in ViewPager
    primarykey
    data
    text
    <p>I have a question about how to best load data for each page in ViewPager.</p> <p>Before applying ViewPager for my mail app, since I only have one page loaded when viewing mail, one background thread (LoadMailDetailThread) was used to load mail data and bind it to ListView for that particular page to show data. Within LoadMailDetailThread, it does tasks such as - Load Mail based on input message id. - Set mail to read status. - Parses mail content to add hyperlink to each url. - Parses mail content to add link to each phone number. - Bind it to ListView. etc.</p> <p>This has worked well for many app version before using ViewPager.</p> <p>Now I need to implement a function which allow users to swipe to change mail. After applying ViewPager, I now have max three pages loaded at any given time. To reuse the existing code, each page uses LoadMailDetailThread to load mail data and bind it to ListView in that page. But in this new design not every task is needed to be done if the page is not a visible page, e.g. set mail to read status, parse mail. So to let LoadMailDetailThread differentiate between whether we are currently loading for visible page or not, I have a flag passed into it (1 means visible, 0 means not visible). So if we are loading the visible page, we will set mail to read status and do parsing, else we will do these tasks in onPageSelected.</p> <p>I don't think this is a very good design because in LoadMailDetailThread, I have many if statements such as if(taskType == VISIBLE) { } else if (taskType == NONVISIBLE) { }</p> <p>all over the place.</p> <p>My question is, is there a recommended way, or pattern to solve this kind of problem? Writing separate classes for visible and non visible class? or modify LoadMailDetailThread to only do the generic tasks (load mail) and let onPageSelected do the specifics (set mail to read status, parses content)?</p> <p>thanks</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload