ProgressDialog not showing while performing a task

后端 未结 3 1682
青春惊慌失措
青春惊慌失措 2020-12-17 18:02

I have a backup routine that copies everything from one folder to an external SD card which works perfectly. I\'m trying to get an nice popup dialog box that shows when it\'

3条回答
  •  醉酒成梦
    2020-12-17 18:34

    You run long running tasks in a Thread or with an AsyncTask. Then your ProgressDialog will show up.

    Do something like:

    public void doBackup(View view) throws IOException{
        final ProgressDialog pd = new ProgressDialog(this);
        pd.setProgressStyle(ProgressDialog.STYLE_SPINNER);
        pd.setMessage("Running backup. Do not unplug drive");
        pd.setIndeterminate(true);
        pd.setCancelable(false);
        pd.show();
        Thread mThread = new Thread() {
            @Override
            public void run() {
                File source = new File("/mnt/extSdCard/DirectEnquiries"); 
                File dest = new File("/mnt/UsbDriveA/Backup");
                copyDirectory(source, dest);
                pd.dismiss();
            }
        };
        mThread.start();
    }
    

提交回复
热议问题