开发者

Insert progress spinner into splashscreen android

开发者 https://www.devze.com 2023-01-17 03:18 出处:网络
In my android application,i would like to place a progress bar such that it shows the user that the data is gettin开发者_如何学Pythong downloadedand gets dismissed once the data is loaded.

In my android application,i would like to place a progress bar such that it shows the user that the data is gettin开发者_如何学Pythong downloaded and gets dismissed once the data is loaded.

Is there any way that i can achieve this.

Thanks in advance:)


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

精彩评论

暂无评论...
验证码 换一张
取 消