2

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.

Tobias
  • 7,086
  • 10
  • 47
  • 76
hassanadnan
  • 425
  • 3
  • 8
  • 17

3 Answers3

3

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

Vladimir Ivanov
  • 42,109
  • 17
  • 76
  • 102
1

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);
Farhan
  • 13,012
  • 2
  • 32
  • 58
  • ok i just test one more method.. its this: Create your progress dialoge like, progressDialoge p = ProgressDialoge.show(myContextVariable,"title","message"); where myContextVariable is initialized like this in onCreate(): myContextVariable = this; // This "this" is very important; otherwise you will probably get a error... now in handler use .Cancel function to cancel the dialoge.... hope it works... – Farhan Mar 25 '11 at 13:26
0

Check this thread : ProgressDialog dismissal in android

Community
  • 1
  • 1
Vinayak Bevinakatti
  • 39,623
  • 25
  • 106
  • 137