Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Store Room Database in Google Drive App Folder?

I'm not yet familiar with Room and Google Drive API and I would like to know if it's possible to create a Room database and store it in the hidden Google Drive App folder for sync across devices. If anyone implemented something similar, a short example would be great. Thanks!

Edit:

What about using LiveData to observe when something changes in the Room database and then trigger a sync to Google Drive?

like image 253
adriennoir Avatar asked Nov 07 '22 21:11

adriennoir


1 Answers

Even if it is possible, it might not work reliably.

SQLite needs direct filesystem access to the database. Room does not change that. I have never used the Google Drive API, and so I do not know if it gives you direct filesystem access (e.g., java.io.File) to the content. If it does not, then what you want is not possible.

The reliability issue comes from the fact that Google Drive is a separate app from your own. Drive should only be working with the file when your app is not actively using the database. I do not know if Drive is taking any steps to ensure this. Otherwise, you could get data corruption. You will also get data corruption if the user modifies the data on multiple devices before Drive has done any sync work (e.g., one of the devices is presently offline).

like image 136
CommonsWare Avatar answered Nov 15 '22 10:11

CommonsWare