Search code examples
androidandroid-progressbarandroid-loadermanagerandroid-loader

Is it a bad idea to daisy-chain Android Loaders?


I need to get data from 2 sources online and would like to show progress of each as I do so. Once the data has been collected I can populate a listview.

My current implementation is that MyActivity implements LoaderCallbacks which in turn creates an instance of MyDataLoader (a class which extends AsyncTaskLoader). In the loadInBackground method of MyDataLoader it fetches the data from all sources and populates a Sqlite db. This db can then be used throughout.

The problem is that I am not giving the user any feedback as to where in the process we are.

So I was thinking of somehow daisy-chaining loaders using getLoaderManager().initLoader to create my loaders and then to iterate through the loaders in the loadermanager one at a time. As each loader finishes and returns to onLoadFinished I have an opportunity to set the text of a progressDialog to indicate the progress.

Is this a bad idea? Is there a simpler and better way?


Solution

  • It's not possible because Loaders load data in the background on separate threads... data is not loaded "sequentially" and thus showing progress in onLoadFinished won't give you an accurate picture of how much progress has actually been made.

    All the user needs to know is that data is being loaded in the background. Even launching an entire dialog is a bit overkill and kind of disrupts the user experience in my opinion. Two alternatives off the top of my head are to:

    1. Show an indeterminate progress icon in your layout or action bar.

    2. Show a grayed-out TextView that says Loading... in the center of the layout. The TextView is finally hidden when the data has been retrieved from the web and is ready to be displayed on screen. Several Google-made apps choose this option, for example, Google Analytics.