Android is programmed to load methods that are waiting for ProgressDialog

  • 2020-12-05 17:22:35
  • OfStack

This article illustrates how Android can program to load and wait for ProgressDialog. To share for your reference, the details are as follows:

The class that displays progressDialog:


import android.app.ProgressDialog;
import android.content.Context;
import android.content.DialogInterface;
import android.content.DialogInterface.OnCancelListener;
public class ShowProgressDialog {
  public static ProgressDialog wait;
  public static void show(Context context,String msg,Thread thread) {
    final Thread th = thread;
    wait = new ProgressDialog(context);
    // Set the style to circle 
    wait.setProgressStyle(ProgressDialog.STYLE_SPINNER);
    wait.setTitle(null);
    wait.setIcon(null);
    // Set prompt message 
    wait.setMessage(msg);
    // Sets whether you can cancel with the return key 
    wait.setCancelable(true);
    wait.setIndeterminate(false);
    // Set to unlisten 
    wait.setOnCancelListener(new OnCancelListener() {
      @Override
      public void onCancel(DialogInterface dialog) {
        th.interrupt();
      }
    });
    wait.show();
  }
}

When called, progressDialog is displayed as the main thread, and another thread is used for business processing. ShowProgressDialog. wait. dismiss() is called when the business processing is finished. Close the progressDialog. If the prompt message is needed after processing, it is not feasible directly in the business thread, and the interaction between the thread and activity needs to be realized through Handler

I hope this article has been helpful in Android programming.


Related articles: