Choosing a Storage Target

You could back up or export the data to some file on the filesystem. On newer versions of Android, though, your ability to work with external storage starts to become more restricted.

You could back up or export the data to some location that the user chooses through the Storage Access Framework, such as via ACTION_CREATE_DOCUMENT.

You could back up the data to some server. In this case, the safest thing to do is to back up the data to some file on the filesystem first, then upload the file. As we will see later in the chapter, it is important for the database to be closed at the time you are making the backup copy, so we want the backup process to be as fast as possible. Directly streaming the data to some server will be a lot slower than making a local copy, due to network speeds.

It may be that your repository can be oblivious (somewhat) to these decisions. If you tell the repository to back up to a Uri, then whether that Uri points to a local file or to a location from ACTION_CREATE_DOCUMENT is immaterial. Your UI and viewmodel can make the decision of exactly where the copy is made.


Prev Table of Contents Next

This book is licensed under the Creative Commons Attribution-ShareAlike 4.0 International license.