title: How to change the activity when the progress bar ends in Android?
body: <p>I want to change the activity after the progress bar ends. Means progress Bar thread ends. I am adding the <code>activity2</code> after the thread. But the <code>activity2</code> starts as the application runs. Why is it so?  </p>
  
  <pre><code>   @Override
      protected void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.activity_main);
  
          progressBar = (ProgressBar) findViewById(R.id.progressBar1);
          new Thread(new Runnable() {
              public void run() {
                  while (progressStatus &lt; 100) {
                      progressStatus += 1;
                      handler.post(new Runnable() {
                          public void run() {
                              progressBar.setProgress(progressStatus);
                          }
                      });
                      try {
                          Thread.sleep(20);
                      } catch (InterruptedException e) {
                          e.printStackTrace();
                      }
                  }
              }
          }).start();
  
  
          Intent myIntent = new Intent(getApplicationContext(), activity2.class);
          myIntent.putExtra("key", "......"); //Optional parameters
          startActivity(myIntent);
  </code></pre>