Good afternoon, I wrote a method for deleting files, after calling it, files are not deleted immediately, but only after they are updated and one of them is opened for viewing. What could be the reason?

private void delFile() { File folder = new File("/storage/emulated/0/Pictures/Photo_and_Video"); File[] listOfFiles = folder.listFiles(); for(File f : listOfFiles ) { f.delete(); //удаление файлов из списка поочередно. } 
  • Arrange the punctuation marks, but it is not clear what reason you want to find out - Android Android
  • @AndroidAndroid paraphras a little - Varg Sieg
  • one
    Probably the reason is in the file browser, which does not update the file list after deletion. - woesss
  • @woesss is possible in more detail? - Varg Sieg

1 answer 1

If f.delete() == true then you are doing everything right. Re-opening the files is not necessary (whatever that means).

Most likely you incorrectly checks whether the file was deleted.

  • Much more correct, after calling the delFile () method, I open the folder, I look at everything in place and even previews for everyone, then I update the folder, the preview disappears, but the files remain, I open one of them, there is no image, I close the file and after 2 seconds they disappear. And while these actions are not done, they will not go anywhere. - Varg Sieg
  • one
    Apparently you are checking with some kind of file manager. And they usually cache data. check this: File.exist () - Egor tepikin