Manohar
Manohar

Reputation: 23404

Display Progress bar while delay?

In my app i want to have a delay of 5 seconds and in this five seconds user should see progress dialog i tried this

    progressdialog.show();
  try {
            Thread.sleep(5000);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }

    progressdialog.dismiss();

but while Thread is sleeping the progessdialog also wont show .

Upvotes: 1

Views: 3511

Answers (2)

Latief Anwar
Latief Anwar

Reputation: 1868

        progressDialog.show();

        new Handler().postDelayed(new Runnable() {
            @Override
            public void run() {
                progressDialog.dismiss();
            }
        },3000);

Upvotes: 1

Manohar
Manohar

Reputation: 23404

 new CountDownTimer(6000, 1000) {
            public void onFinish() {
               mProgressDialog.dismiss();
              // my whole code
            }

            public void onTick(long millisUntilFinished) {
                mProgressDialog.show();
            }
        }.start();

This works fine

Upvotes: 3

Related Questions