Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
747 views
in Technique[技术] by (71.8m points)

android - "Rotating wheel" progress dialog while deleting folder from SD card

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

This answer is also all over StakcOverflow. Use AsyncTask which will run on a different thread and has three stages... One pre which you will load the wheel in and the post which you will dismiss it when done... And then the background which is the actual work.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...