Android: save the file permanently (even after clear data / deletion)

I would like to know if there is a way to keep a small amount of data forever.
Constantly, I mean that I want the data to be saved even if the user deletes the application / data for remote applications.
I know that general settings and databases are deleted when the user clears the application / application to remove applications.

I also know that I can save material to an SD card, but what if the device does not have an SD card / SD card is unmounted?

I think that the best option would be to save the data on the deviceโ€™s internal memory, but can this be done without deleting the data while cleaning the uninstalls application / application?

+6
source share
2 answers

You should not do this, you should not force users to store data on their phones without their consent.

In any case, the application data directory will be deleted after deletion, but NOT after the update.

The only way to have persistent data is to use an SD card, but again, users will not like having data on their card after uninstalling the application.

Or you may consider:

  • Saving data on a remote server with any authentication to receive it
  • Using the Backup Data Service
+12
source

Environment.getDataDirectory() is at least one directory in which you can save files. It is located on the internal memory (/ data).

In one case, I use it to determine if a service is running; I create a .lock file there and always check if it exists.

+1
source

Source: https://habr.com/ru/post/888890/


All Articles