How to backup Realm DB in Android before deleting the Realm file. Is there any way to restore the backup file? -
i working on android application deleting realm before copying new data realm. there way can take backup of data before deleting , restore if wrong when using realm.copytorealm() ?
realm.writecopyto
might helpful case. can find doc here.
//backup realm orgrealm = realm.getinstance(orgconfig); orgrealm.writecopyto(pathtobackup); orgrealm.close(); //restore realm.deleterealm(orgconfig); realm backuprealm = realm.getinstance(backupconfig); backuprealm.writecopyto(pathtorestore); backuprealm.close(); orgrealm = realm.getinstance(orgconfig);
but in case, simpler , faster move realm file place backup, , move when want restore it. realm file path, try:
realm.getpath();
Comments
Post a Comment