Last active
February 18, 2020 08:37
-
-
Save 19Site/39a6d1c40794de16dfd97f2da7ef9f16 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public static void main(String... args) { | |
AsyncTask<String, Integer, Boolean> task = new AsyncTask<String, Integer, Boolean>() { | |
// loading dialog | |
AlertDialog dialog = (new AlertDialog.Builder(context)).setCancelable(false).setMessage("loading").create(); | |
@Override | |
protected Boolean doInBackground(String... strings) { | |
publishProgress(1); | |
doHttp1(); | |
publishProgress(2); | |
doHttp2(); | |
publishProgress(3); | |
doHttp3(); | |
publishProgress(4); | |
return true; | |
} | |
@Override | |
protected void onPostExecute(Boolean aBoolean) { | |
super.onPostExecute(aBoolean); | |
// todo | |
} | |
@Override | |
protected void onProgressUpdate(Integer... values) { | |
super.onProgressUpdate(values); | |
switch (values[0]) { | |
case 1: | |
dialog.show(); | |
case 2: | |
case 3: | |
dialog.setMessage("progress " + values[0]); | |
break; | |
case 4: | |
default: | |
dialog.dismiss(); | |
} | |
} | |
private void doHttp1() { | |
// do http request | |
} | |
private void doHttp2() { | |
// do http request | |
} | |
private void doHttp3() { | |
// do http request | |
} | |
}; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment