1

What technique might I use to wait for my ContentProvider to fill-up before I start a specific activity? I am using a SyncAdapter to load the ContentProvider.

Normally I don't want to block my UI. But my app is a data app and the data is coming from remote server; from there it is saved in my ContentProvider (sqlite db). So I show the user a SplashActivity. I want the content provider to load before I take the user to the MainActivity. How do I do that? Again, my app is SplashActivity -> MainActivity

Nouvel Travay
  • 6,292
  • 13
  • 40
  • 65

2 Answers2

1

You can user AsyncTask

Like:

private class DownloadFilesTask extends AsyncTask<URL, Integer, Long> {

   //MAKE YOUR REQUEST HERE
   protected Long doInBackground(URL... urls) {
         int count = urls.length;
         long totalSize = 0;
         for (int i = 0; i < count; i++) {
             totalSize += Downloader.downloadFile(urls[i]);
             publishProgress((int) ((i / (float) count) * 100));
             // Escape early if cancel() is called
             if (isCancelled()) break;
         }
         return totalSize;
     }

     protected void onProgressUpdate(Integer... progress) {
         setProgressPercent(progress[0]);
     }

     //When finish the request CALL MainActivity HERE
     protected void onPostExecute(Long result) {
         showDialog("Downloaded " + result + " bytes");
     }
 }

Or use the Volley library

Hugo Landim
  • 169
  • 8
0

I ended up solving this using a BroadcastReceiver. An AsyncTask would not work because I am using a SyncAdapter. So I wait for the SyncAdapter to finish and then send a Broadcast. I am not sure how bad this can get as the internet may be slow for some users. But so far it works.

Nouvel Travay
  • 6,292
  • 13
  • 40
  • 65