0

I am fully aware on how to display progress dialogues in my application. I just want to know if there is anyway that we can set a "timeout" interval for this progress dialog. [I mean is there any API for this]

I can always run a thread for this, but thought it would be better if there was an inbuilt API already..

Anand Sainath
  • 1,807
  • 3
  • 22
  • 48

2 Answers2

1

There is no built-in api. Just use AsyncTask or thread, how you have already mentioned.

Vladimir Ivanov
  • 42,730
  • 18
  • 77
  • 103
0

You can use a Handler as well (post a delayed message to the handler and the handler will close the dialog). I don't know any way to tell the dialog to close itself after a given time.

private ProgressDialog dialog;
private Handler closeHandler = new Handler() {
  public void handleMessage(Message msg) {
    if (dialog!=null) dialog.dismiss();
  }
};


public void openDialog() {
  // Open the dialog

  // Close it after 2 seconds
  closeHandler.sendEmptyMessageDelayed(0, 2000);
}
Vincent Mimoun-Prat
  • 28,208
  • 16
  • 81
  • 124
  • I am currently using the handler way to do that. It is a progress dialog for downloading some content from internet. What happens here is if in the middle of the downloading process, the internet connectivity goes away, the progress dialog keeps repeating forever. This is because I have called the dismiss method only after the download is complete. – Anand Sainath Mar 25 '11 at 10:57
  • You should set a timeout on your Http request as well else, you will be keeping a download in progress during the whole life of your activity. IMHO you are solving the problem with the wrong solution. – Vincent Mimoun-Prat Mar 25 '11 at 11:00
  • 2
    Then listen for network connection and if connectivity goes , dismiss the dialog and any web operations. check http://stackoverflow.com/questions/3307237/how-can-i-monitor-the-network-connection-status-in-android – sat Mar 25 '11 at 11:00
  • 1
    Ain't any exception thrown when connection goes down? – Vladimir Ivanov Mar 25 '11 at 11:00