In my last post, I talked about two techniques to store app data and files in Android. In this post, I will talk about the other two.
When you attempt to buy an Android device you will find how much SD card capacity that the device can support and the SD card is external storage. Every Android device support external storage as a shared storage space to save your files. You cannot be guaranteed this storage space will be available or accessible all the time. The files saved in the external storage are world-readable and can be modified by the user when connecting the device to a computer and enable transfer files. So if you try to access a file in the external storage you should first check if the external storage is available and also check if the file you try to access is also available. Most often the files that you saved in the external storage you want them to be accessible for the user even if the user uninstalls your app such as photos, PDF files .. etc. Android provides standard public directories for these kinds of files so you can find them in a specific location, so you can find all your photos in one location, all your music in one location .. etc.
You can save your files in external storage in an app-specific directory if you need more space than the internal storage can provide, but these directories will be removed if you uninstall the app, but also these files are not guaranteed to be accessible all the time because the user might remove the storage SD card, also these files will still be a world-readable, just their location will not be shared with other apps.
If you choose to store the app structured data in a database; Android provides full support for SQLite database. The database you created will be only accessible by your app.
Android developer website recommends using The Room library to create and interact with your database. I will make a post about The Room library in the future.
Those were four techniques to store your app data and files but which one to choose?
The one you choose depends on your need and requirements such as how much space your data need and what kind of data you need to store and whether data should be only private to your app or accessible to other apps and also the user. Keep in mind that all these options are intended for app-private data except for some types of files on the external storage.
So that’s it for this post. Till my next post.