title: Show ProgressBar for a few seconds in Android
body: <p>I have to wait some seconds in my Android App and I want to show a progress bar during this time, how can I do this?</p>
  
  <p>for example :</p>
  
  <pre><code>@Override
  protected void onCreate(Bundle savedInstanceState) {
  
      timeForShow(5 //second);
  
  }
  .
  .
  .
  
  private void timeForShow(long mytime){
  
  myprogress.setVisibility(View.VISIBLE);   
  Waiting for mytime...
  myprogress.setVisibility(View.GONE); 
  
  }
  </code></pre>
  
  <hr>
  
  <p>this is my code but it does not work:</p>
  
  <pre><code>Long timerforprogressbar ;
  
  @Override
  protected void onCreate(Bundle savedInstanceState) {
  
      timerforprogressbar = (long) 5000 ;
      new MyProgressBar().execute((Void)null);
  
  }
  .
  
  .
  
  .
  
  
  class MyProgressBar extends AsyncTask&lt;Void, Void, Void&gt;{
  
      @Override
      protected Void doInBackground(Void... params) {
          // TODO Auto-generated method stub
          progressbar.setVisibility(View.VISIBLE);
          try {
              Thread.sleep(timerforprogressbar);
          } catch (InterruptedException e) {
              // TODO Auto-generated catch block
              e.printStackTrace();
          }
          return null;
      }
  
      @Override
      protected void onPostExecute(Void result) {
          // TODO Auto-generated method stub
          super.onPostExecute(result);
          progressbar.setVisibility(View.GONE);
      }
  
  }
  </code></pre>
  
  <p>my progress bar :</p>
  
  <pre><code>    &lt;ProgressBar
          android:id="@+id/progressBar"
          style="?android:attr/progressBarStyleLarge"
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"
          android:visibility="gone"
          android:indeterminateDrawable="@drawable/progress" &gt;
      &lt;/ProgressBar&gt;
  </code></pre>
  
  <p>progressbar is my progress bar,plz help me,tnx.</p>