0

I use this Tutorial to create custom Progressbar and it works .

But I want to start new activity when progress bar go to 100% .

anyone can help to put start new activity code in correct place?

3
  • Post the code where you're updating the progressbar's progress. Sep 21, 2012 at 15:21
  • full source is here : jagsaund.com/blog/2011/11/6/… I use this code
    – user1517313
    Sep 21, 2012 at 15:24
  • I suggest you start the new activity when the old one finishes. That might not be when the PB = 100% Sep 21, 2012 at 15:25

3 Answers 3

4

You can check if the progress has reached the maximum possible while you're setting it, like this:

@Override
  public synchronized void setProgress(int progress) {
    super.setProgress(progress);

    // the setProgress super will not change the details of the progress bar
    // anymore so we need to force an update to redraw the progress bar
    invalidate();

    if(progress >= getMax()) {
        Intent intent....
    }
  }
1

You can call the onContinue function timer thread and set the intent to next activity and register the activity name in manifest file.

@Override
   public void onCreate(final Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.progress);
    mProgressBar = (ProgressBar)findViewById(R.id.adprogress_progressBar);
    final Thread timerThread = new Thread() {
        @Override
            public void run() {
            mbActive = true;
            try {
                int waited = 0;
                    while(mbActive && (waited < TIMER_RUNTIME)) {
                        sleep(200);
                        if(mbActive) {
                            waited += 200;
                            updateProgress(waited);
                        }
                    }
            } catch(InterruptedException e) {
        } finally {
                onContinue();
        }
      }
    };
    timerThread.start();
}
@Override
public void onDestroy() {
    super.onDestroy();
}
public void updateProgress(final int timePassed) {
    if(null != mProgressBar) {
        final int progress = mProgressBar.getMax() * timePassed / TIMER_RUNTIME;
        mProgressBar.setProgress(progress);
    }
}

public void onContinue() {
    Intent intd=new Intent(this,MainActivity.class);
    startActivity(intd);
    }
0

Try this...

new Thread(new Runnable() {
    public void run() {
        while (progressStatus < 100) {
            progressStatus += 5;
            // Update the progress bar and display the current value in the text view
            handler.post(new Runnable() {
                public void run() {
                    progressBar.setProgress(progressStatus);
                    textView.setText("Loading "+progressStatus+"/"+progressBar.getMax());
                }
            });
            try {
                // Sleep for 200 milliseconds. Just to display the progress slowly
                Thread.sleep(200);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
    }

    **Intent intent = new Intent(Main_Activity.this, Send_Email.class);
        startActivity(intent);**
    }
}).start();

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.