Skip to content

Instantly share code, notes, and snippets.

@19Site
Last active February 18, 2020 08:37
Show Gist options
  • Save 19Site/39a6d1c40794de16dfd97f2da7ef9f16 to your computer and use it in GitHub Desktop.
Save 19Site/39a6d1c40794de16dfd97f2da7ef9f16 to your computer and use it in GitHub Desktop.
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