Paste progress scroll in android popup

In my Android app, I would like to put a progress bar so that it shows the user that the data is loading and quitting after the data is loaded.

Is there a way I can achieve this.

Thanks in advance:)

+3
source share
1 answer

You can achieve this with the AsyncTask class.

In these three steps you must follow,

  • you need to run ProgreesDialog in onPreExecute().
  • doInBackground() takes charge of the boot process.
  • onPostExcecute()starts after the second step. on this you can reject your progress dialog, start a new activity and end your surge.

, . .

:

  private class Task extends AsyncTask<Void, Void, Void> {
    private final ProgressDialog dialog = new ProgressDialog(
            your_class.this);

    // can use UI thread here
    protected void onPreExecute() {
        this.dialog.setMessage("Loading...");
        this.dialog.setCancelable(false);
        this.dialog.show();
    }

    @Override
    protected Void doInBackground(Void... params) {
        try {
            // do downloading images code here
        } catch (Exception e) {

        }
        return null;

    }

    protected void onPostExecute(Void result) {
           //start the another activity and then close your current activity here.
        if (this.dialog.isShowing()) {
            this.dialog.dismiss();
        }
    }
}
+3

All Articles