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,238
  • 10
  • 46
  • 77
hassanadnan
  • 435
  • 3
  • 8
  • 17

3 Answers3

3

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

Vladimir Ivanov
  • 42,730
  • 18
  • 77
  • 103
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,290
  • 2
  • 33
  • 59
  • 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
  • 40,205
  • 25
  • 108
  • 139