Android Back Button and Progress Dialog

前端 未结 9 2063
攒了一身酷
攒了一身酷 2021-01-31 03:24

I have an AsyncTask that shows a progressDialog whilst working (it calls runOnUiThread from within doInBackground to show the progress dialog).

<
9条回答
  •  星月不相逢
    2021-01-31 03:59

    Its very simple just copy the below code and paste within Async task..

    ProgressDialog dialog;

    @Override
    protected void onPreExecute() {
    
        dialog = new ProgressDialog(MainActivity.this) {
            @Override
            public void onBackPressed() {
                dialog.cancel();
                dialog.dismiss();
            }
        };
        // dialog.setTitle("file is..");//its optional If u want set title in progress
        // bar
        dialog.setMessage("Loading file....");
        dialog.setCancelable(false);
    
        dialog.show();
    
    }
    

提交回复
热议问题