How to show progress dialog in Android?

后端 未结 16 2940
予麋鹿
予麋鹿 2020-11-28 07:40

I want to show ProgressDialog when I click on Login button and it takes time to move to another page. How can I do this?

16条回答
  •  眼角桃花
    2020-11-28 08:20

    when you call in oncreate()

    new LoginAsyncTask ().execute();
    

    Here how to use in flow..

    ProgressDialog progressDialog;
    
      private class LoginAsyncTask extends AsyncTask {
      @Override
        protected void onPreExecute() {
            progressDialog= new ProgressDialog(MainActivity.this);
            progressDialog.setMessage("Please wait...");
            progressDialog.show();
            super.onPreExecute();
        }
    
         protected Void doInBackground(Void... args) {
            // Parsse response data
            return null;
         }
    
         protected void onPostExecute(Void result) {
            if (progressDialog.isShowing())
                            progressDialog.dismiss();
            //move activity
            super.onPostExecute(result);
         }
     }
    

提交回复
热议问题