我有一个备份例程,可以将所有内容从一个文件夹复制到外部SD卡,完美无缺.我正在尝试获得一个很好的弹出对话框,显示它正在运行但它没有显示.甚至没有尝试运行(但备份确实完成).
这是我目前的代码:
public void doBackup(View view) throws IOException{
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();
File source = new File("/mnt/extSdCard/DirectEnquiries");
File dest = new File("/mnt/UsbDriveA/Backup");
copyDirectory(source, dest);
pd.dismiss();
}
解决方法:
您在线程或AsyncTask中运行长时间运行的任务.然后你的ProgressDialog会出现.
做类似的事情:
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();
}