在开始特定活动之前,我可以使用什么技术等待ContentProvider填满?我正在使用SyncAdapter加载ContentProvider。

通常,我不想阻止我的UI。但是我的应用程序是数据应用程序,数据来自远程服务器。从那里将其保存在我的ContentProvider(sqlite db)中。因此,我向用户展示了SplashActivity。我希望内容提供商在将用户带到MainActivity之前加载。我怎么做?同样,我的应用是SplashActivity -> MainActivity

最佳答案

您可以使用AsyncTask

喜欢:

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");
     }
 }


或使用Volley library

10-05 20:59
查看更多