I want to display simple progress dialog with rotating wheel, while deleting folder from SD card. I have a following piece of code:
ProgressDialog dialog = ProgressDialog.show(this, "",
"Please wait for few seconds...", true);
private void deleteCache() {
File f = new File(Environment.getExternalStorageDirectory()
.getAbsoluteFile() + Constants.DATA_DIR);
deleteDirectory(f);
dialog.dismiss();
}
private void deleteDirectory(File path) {
if (path.exists()) {
File[] files = path.listFiles();
for (int i = 0; i < files.length; i++) {
if (files[i].isDirectory()) {
deleteDirectory(files[i]);
} else {
files[i].delete();
}
}
}
return (path.delete());
}
Which is supposed to show dialog before deleteDirectory(f);
and dissmis it after it ends. But I never see any dialog, event though the folder is being deleted.
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…