Remmyabhavan
Remmyabhavan

Reputation: 1719

Insert progress spinner into splashscreen android

In my android application,i would like to place a progress bar such that it shows the user that the data is getting downloaded and gets dismissed once the data is loaded.

Is there any way that i can achieve this.

Thanks in advance:)

Upvotes: 3

Views: 3438

Answers (1)

Praveen
Praveen

Reputation: 91175

You can achieve it by AsyncTask class.

In that three steps you have to follow,

  1. you have to start the ProgreesDialog in onPreExecute().
  2. doInBackground() takes control of the Downloading Progress.
  3. onPostExcecute() runs after the second step. on that you can dismiss your progressdialog, start the New Activity and finish your splashscreen.

More Info, check the Documentation. It has a explanation with example code.

CODE:

  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();
        }
    }
}

Upvotes: 3

Related Questions