Here's source comment for this method:
Note that on Android, the application lifecycle does not include VM termination, so calling this method will not ensure that files are deleted. Instead, you should use the most appropriate out of:
* Use a {@code finally} clause to manually invoke {@link #delete}.
* Maintain your own set of files to delete, and process it at an appropriate point
in your application's lifecycle.
* Use the Unix trick of deleting the file as soon as all readers and writers have
opened it. No new readers/writers will be able to access the file, but all existing
ones will still have access until the last one closes the file.
Can anyone explain to me what is the "Unix trick" mentioned in it and how to use it?
This answer has a good explanation: https://stackoverflow.com/a/5219960/200508. Basically, it means that "deleting" a file on a Unix system doesn't immediately erase it from disk; instead, it just deletes the reference to that file from the directory it's in. The file isn't actually erased until all processes which are using it terminate. Thus, you can open a temporary file and immediately delete it, and then whenever the program terminates it will be automatically erased.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With