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

Popular posts from this blog

OpenCV OpenCL: Convert Mat to Bitmap in JNI Layer for Android -

android - org.xmlpull.v1.XmlPullParserException: expected: START_TAG {http://schemas.xmlsoap.org/soap/envelope/}Envelope -

python - How to remove the Xframe Options header in django? -