Realm.writeCopyTo may be useful for this case. Here you can find the doc .
//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 your case, it would be much simpler and faster to just move your Realm file to a backup location and move it back when you want to restore it. To get the path to the Realm file, try:
realm.getPath();
beeender
source share