在日志数据中未使用Android中的AsyncTask显示进度对话框

时间:2018-10-19 19:31:48

标签: java android android-asynctask

class StudentTask extends android.os.AsyncTask<Void, String, String> {


        Context mContext;
        private ProgressDialog myDialog;
        StudentTask(Context loginActivity){
         this.mContext=loginActivity;
        }
        @Override
        protected void onPreExecute() {

            Log.e("async", "onPreExecute: try to fetch data " );
            myDialog=new ProgressDialog(mContext);
            myDialog.setTitle("Loading!");
            myDialog.setIndeterminate(true);
            myDialog.setMessage("Please Wait!");
            myDialog.show();
            super.onPreExecute();
        }

        @Override
        protected void onPostExecute(String s) {
            super.onPostExecute(s);
            if(s!=null){
                myDialog.dismiss();
                Log.e("async","result is shown" );
            }
         }

在MainActivity.java中

StudentTask studentTask = new StudentTask(LoginActivity.this);
json = studentTask.execute().get();

0 个答案:

没有答案