De linne
De linne

Reputation: 53

ProgressDialog closing onClick

I start an AsyncTask to load a file that takes some time. To inform the user I'm showing a ProgressDialog, however if I touch the screen the ProgressDialog closes immediately. What could be the cause of this?

 public LoadTask(Activity activity, FaceRecognizer recognizer,SecretKey key) {
    this.key = key;     
    this.recognizer = recognizer;       
    dialog = new ProgressDialog(activity);

}

@Override
protected void onPreExecute() {
    dialog.setMessage("Loading the recognizer...");
    dialog.show();
}

@Override
protected Boolean doInBackground(Void... params) {
    recognizer.load(key);
    return null;
}

@Override
protected void onPostExecute(Boolean result) {

    if (dialog.isShowing()) {
        dialog.dismiss();
    }       

Upvotes: 4

Views: 675

Answers (3)

Mehul Ranpara
Mehul Ranpara

Reputation: 4255

use this...

public LoadTask(Activity activity, FaceRecognizer recognizer,SecretKey key) {
    this.key = key;     
    this.recognizer = recognizer;       
    dialog = new ProgressDialog(activity);
     /////////////////////////////////////////// 
    dialog.setCancelable(false);
           //or////////
    dialog.setCanceledOnTouchOutside(false);
}

Upvotes: 6

Pierry
Pierry

Reputation: 989

Try:

dialog.setIndeterminate();
dialog.setCancelable(false);

Upvotes: 0

toadzky
toadzky

Reputation: 3846

Try: dialog.setCanceledOnTouchOutside(false)

Upvotes: 1

Related Questions