title: How to handle data loading with asynctask
body: <p>I am loading data for a log. It runs smoothly. However, I added a gone indeterminate progress bar below toolbar which always shows every time Asynctask is called. </p>
  
  <ol>
  <li>Is it possible to avoid showing this when data was loaded so fast? </li>
  <li>Is <code>thread.sleep</code> recommended in this? </li>
  <li>Or a progressbar is not needed even loading 500 and above records?</li>
  </ol>
  
  <p>Here's my code:</p>
  
  <pre><code>public void refreshList(String status) {
      String id = String.valueOf(getArguments().getInt("ID"));
  
      String paramsValue[] = new String[2];
      paramsValue[0] = id;
      paramsValue[1] = status;
      new LogsTask(this).execute(paramsValue);
  
  }
  
  private static class LogsTask extends AsyncTask&lt;String[], Integer, LinkedHashMap&lt;Integer, ValuesExtension&gt;&gt; {
      String paramsValue[];
  
      LogsFragment logsFragment;
      WeakReference&lt;LogsFragment&gt; fragmentWeakReference;
  
      LogsTask(LogsFragment logsFragment) {
          fragmentWeakReference = new WeakReference&lt;&gt;(logsFragment);
      }
  
  
      @Override
      protected void onPreExecute() {
          logsFragment = fragmentWeakReference.get();
          logsFragment.pbLogs.setVisibility(View.VISIBLE);    
      }
  
      @Override
      protected LinkedHashMap&lt;Integer, ValuesExtension&gt; doInBackground(String[]... params) {
          Cursor dbReader = null;
  
          DBHelper dbHelper = new DBHelper(logsFragment.getContext());
          LinkedHashMap&lt;Integer, ValuesExtension&gt; logsMap = new LinkedHashMap&lt;&gt;();
  
          try {              
              dbHelper.open();
  
              if (dbReader.getCount() &gt; 0) {
                  while (dbReader.moveToNext()) {
                      try {
                          /* LOADING OF DATA */
                          logsMap.put("values", value);
  
                          Thread.sleep(250); // is this important when loading data?
                      } catch (InterruptedException | ParseException e) {
                          e.printStackTrace();
                      }
                  }
              }
          } catch (SQLException e) {
              return null;
          } finally {
              if (dbReader != null) {
                  dbReader.close();
              }
              dbHelper.close();
          }
          return logsMap;
      }
  
  
      @Override
      protected void onPostExecute(LinkedHashMap&lt;Integer, ValuesExtension&gt; logsMap) {           
          logsFragment.pbLogs.setVisibility(View.GONE);
  
          if (logsMap != null) {
              logsFragment.refreshLog();
          }
  
      }
  }
  </code></pre>