Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Just for some inspiration, here is the general code format that I have used successfully to show a horizontal progress bar which updates while a background task is running. I know it doesn't answer your exact question, but I hope it helps you to find your solution. </p> <pre><code>ProgressDialog myProgressDialog; private void someFunctionThatStartsTheAsyncTask() { new myBackgroundTask.execute(someIntegerArgument); } private class myBackgroundTask extends AsyncTask&lt;Integer, Integer, Boolean&gt; { protected void onPreExecute() { myProgressDialog = new ProgressDialog(myContext); myProgressDialog.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL); myProgressDialog.setTitle("Doing something in background..."); myProgressDialog.setMessage("Please wait..."); myProgressDialog.setCancelable(false); myProgressDialog.setIndeterminate(false); myProgressDialog.setMax(100); myProgressDialog.setProgress(0); myProgressDialog.show(); } protected Boolean doInBackground(Integer... params) { int someVariable = params[0]; boolean success; for (whatever loop conditions) { // some long-running stuff, setting 'success' at some point ... publishProgress(newPositionForProgressBar); } return success; } protected void onProgressUpdate(Integer... progressPosition) { myProgressDialog.setProgress(progressPosition[0]); } protected void onPostExecute(Boolean result) { myProgressDialog.dismiss(); if (result) { //doInBackground returned true } else { //doInBackground returned false } } } </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload