I am searching for methods to support the database of my application with an Android phone. I understand that SQLite databases are simply files, so I'd be prepared to have the ability to just copy the file to SD-card if your are available.
However, I am unsure regarding how I'd prepare my database/activity for backup/restore.
When beginning, my primary activity reads the records in one table within the database and shows these questions
ListView. As proven within the API's "Notes" sample, I've got a cursor that's instantly informed about changes to that particular table (
ListView is instantly up-to-date after i add/remove/update records within the table).
So: After I copy the database file to SD-card, I ought to not have trouble. But let's say the consumer really wants to restore a database file? I can not just copy the file to the information folder, can one (EDIT: ... while a view shows data in the database and therefore maybe holds a wide open connection)?
An amount be "best practice" when applying backup/restore? One approach I have considered is:
- Open a unique "restore" activity that holds no open database connections
finish()for that primary activity to get rid of it and close database connections
- Copy back the database file
- Open a brand new "instance" from the primary activity
finish()for that "restore" activity
Would that be what you want? Thank you for any advice!
But let's say the consumer really wants to restore a database file? I can not just copy the file to the information folder, can one?
Yes, you are able to. As possible slowly move the file from your computer data folder to some folder on your Sdcard, you are able to slowly move the file back in the Sdcard to your data folder.
That which you suggested now, is a great approach, just bear in mind you don't want any open database objects throughout backup/restore.