Search code examples
androidkotlinatomicandroid-file

What are the use cases for AtomicFile?


I'm having trouble understanding the use cases for AtomicFile. Since it does not confer any thread safety, is it just for ensuring no partial/invalid files are written if the app crashes or device loses power during a file write? What would be the purpose of reading a file with AtomicFile?


Solution

  • is it just for ensuring no partial/invalid files are written if the app crashes or device loses power during a file write?

    Yes.

    Adding on to the cases, the OS can kill the process at anytime. AtomicFile should provide atomic guarantees in that case too.