hassanadnan
hassanadnan

Reputation: 435

Android: Unable to Dismiss ProgressDialog

This is how I am creating the PorgressDialog:

... progressBarDialog = new ProgressDialog( context );
                  progressBarDialog.setProgressStyle(ProgressDialog.STYLE_SPINNER);
progressBarDialog.show(this, "Please Wait", "Updating your GPS coordinates",false,true);


//Trigger GPS service to update coordinates
fg.myOnresume(Name);
fg.dontSendSMS();
//Sets the timer at 30 secs
timer= new Timer();
timer.schedule(new startMapActivity());
}
class startMapActivity extends TimerTask 
    {
        @Override
        public void run() 
        {
            //handler.sendEmptyMessage(0);
            Log.d("", "StartMapActivty--->>>run()");
            // Dismissing Dialog Box
            if(progressBarDialog.isShowing())
            {
                progressBarDialog.dismiss();
            }

        }
    }

So Basically after the the timer finished after 30sec I want to dimiss the Dialog, but it is not working :( Please help.

Upvotes: 2

Views: 3353

Answers (3)

Farhan
Farhan

Reputation: 13390

change your code a bit. like:

    Runnable r = new Runnable()
    {

        public void run() 
        {
           // TODO Auto-generated method stub
           //dismiss your dialoge here....
        }
    };

and you can call this like:

  Handler h = new Handler();
  h.postDelayed(r, delayMillis);

Upvotes: 1

Vinayak Bevinakatti
Vinayak Bevinakatti

Reputation: 40503

Check this thread : ProgressDialog dismissal in android

Upvotes: 0

Vladimir Ivanov
Vladimir Ivanov

Reputation: 43098

You can't modify UI from non UI thread. Use handlers to do it.

Upvotes: 3

Related Questions