title: Android studio, why does progressbar disappear before asynctasks are complete?
body: <p>I have the following <strong>Asyntask</strong> in <em><strong>Android Studio</strong></em>.</p>
  
  <p>I'm battling to get the progressbar to work though, the progressbar pops up but then immediately disappears. 
  I want to know:</p>
  
  <blockquote>
    <p>Why is it not waiting for the tasks in the <code>DoInBackground</code> to complete before it disappears?</p>
  </blockquote>
  
  <p>Any advice would be appreciated. I am a beginner so please excuse the silly question if it is indeed a silly question.
  The tasks within <code>DoInBackground</code> are calls to a <em>volley requests</em>, which copy data from a remote <strong>sql database</strong> into the devices <strong>sqlite database</strong>.</p>
  
  <p>Thanks.  </p>
  
  <pre><code>public class AsyncTask extends android.os.AsyncTask&lt;Integer, Integer, String&gt; {
  
          ProgressBar pb;
          int status = 0;
  
          public void setProgressBar(ProgressBar progressBar) {
              this.pb = progressBar;
          }
  
          @Override
          protected void onPreExecute() {
              Log.d(TAG, "zzzzz2: " + "Pre");
              pb.setVisibility(View.VISIBLE);
              super.onPreExecute();
          }
  
  
  
          @Override
              protected String doInBackground(Integer[] objects) {
  
                  Log.d(TAG, "zzzzz2: " + "DoIn");
  
  
  //              if user doesnt exist in db add to server db
                  String strUser = mFirebaseUser.getUid();
                  String strDisplayName = mFirebaseUser.getDisplayName();
                  String strEmail = mFirebaseUser.getEmail();
                  clsServerClass.addUserToServer(strUser, strDisplayName, strEmail, context);
  
                  // load 12 tables into sqlite database
                  clsServerClass.copyTblVersions(context);
                  clsServerClass.copyAnimalClassTable(context);
                  clsServerClass.copyAnimalGroupTable(context);
                  clsServerClass.copyAnimalTable(context);
                  clsServerClass.copyTblSeasons(context);
                  clsServerClass.copyRegions(context);
                  clsServerClass.copyCountries(context);
                  clsServerClass.copyProvinces(context);
                  clsServerClass.copyHotspots(context);
                  clsServerClass.copyHabitats(context);
                  clsServerClass.getMyPlaces(strUser, context);
                  clsServerClass.getSightingsUser(strUser, context);
  
  
                  Cursor cntry = getCsr("animal_unique_key", "tbl_lookup_animals");
                  Log.d(TAG, "yyyya: " + cntry.getCount());
  
                  JSONArray arrayList1 = createListArray("animal_class_key", 1);
                  createListSharedPref("List1_name", "List 1: All birds", "List1_where", arrayList1);
  
                  JSONArray arrayList2 = createListArray("animal_class_key",  2);
                  createListSharedPref("List2_name", "List 2: All Mammals", "List2_where", arrayList2);
  
                  JSONArray arrayList3 = createListArray("animal_class_key", -99);
                  createListSharedPref("List3_name", "List 3: All Animals", "List3_where", arrayList3);
  
                  JSONArray arrayList4 = createListArray("animal_class_key", 3);
                  createListSharedPref("List4_name", "List 4: All Reptiles", "List4_where", arrayList4);
  
                  JSONArray arrayList5 = createListArray("animal_class_key", 4);
                  createListSharedPref("List5_name", "List 5: All Amphibians", "List5_where", arrayList5);
  
                  return null;
  
              }
  
  
  
          @Override
          protected void onProgressUpdate(Integer[] values) {
  
              Log.d(TAG, "zzzzz3: " + "Update");
  
              pb.setProgress(values[0]);
              super.onProgressUpdate(values);
  
          }
  
  
          @Override
          protected void onPostExecute(String s) {
              Log.d(TAG, "zzzzz2: " + "post");
              pb.setVisibility(View.GONE);
              super.onPostExecute(s);
          }
  
  
  
  
          }
  </code></pre>