Get the App
SLTechnology News&Howtos  ›  Internet Technology  › 

Analysis of Android encapsulated pop-up wait box and examples for delay operations such as network requests

Shulou Source: shulou.com Published: 2022-06-01 05:18:16 09月17日 Update

This article shows you the example analysis of Android encapsulated pop-up wait box and delay operation such as network request, the content is concise and easy to understand, it can definitely brighten your eyes. I hope you can get something through the detailed introduction of this article.

The code is very simple. If you don't say much, post it directly.

Public class ShowProgressDialog {

Public static ProgressDialog wait

Public static void show (Context context, String msg) {

Wait = new ProgressDialog (context)

/ / set the style to circle

Wait.setProgressStyle (ProgressDialog.STYLE_SPINNER)

Wait.setTitle (null)

Wait.setIcon (null)

/ / set prompt information

Wait.setMessage (msg)

Wait.show ()

}

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 information

Wait.setMessage (msg)

/ / whether it can be cancelled by the return key

Wait.setCancelable (true)

Wait.setIndeterminate (false)

/ / set to cancel monitoring

Wait.setOnCancelListener (new OnCancelListener () {

@ Override

Public void onCancel (DialogInterface dialog) {

Th.interrupt ()

}

});

Wait.show ()

}

}

The following external call method, because the network request of Android must be operated by thread, and the thread is written with Thread,AsyncTask. After using both, it feels that if the simple background thread does not need to update UI, it is convenient to use Thread, and if there is UI update, use AsyncTask.

Call with the AsyncTask method:

Call ShowProgressDialog.show directly in onPreExecute (mContext, "get the claim document.")

ShowProgressDialog.wait.setMessage (values [0]) in onProgressUpdate; used to wait for text updates displayed during the process

In this way, publishProgress is written in doInBackground ("start getting the order"); the onProgressUpdate will be executed directly.

Finally, add ShowProgressDialog.wait.dismiss () to onPostExecute; you can release the pop-up wait box.

The above is a sample analysis of Android encapsulated pop-up wait boxes and delay operations such as network requests. Have you learned any knowledge or skills? If you want to learn more skills or enrich your knowledge reserve, you are welcome to follow the industry information channel.

Tags: Networks threads updates examples analysis encapsulation information content circles skills methods knowledge style tips concise concise code writing documents can be obtained through the Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Huawei macOS Shulou Technology MariaDB MySQL