Reputation: 893
I'm working on a note app with realm. I'd like to add backup and restore features. So I've been implementing these features as introduced in this page. Here is the user scenario.
It works well if I restart my application. But I want to refresh new data immediately. If I did not restart my application, it works weird. So my question is how can i reload restored realm db so that display restored data without application restarting.
Upvotes: 1
Views: 1744
Reputation: 3565
It is very important that before copying the temp.realm
to default.realm
, all opened Realm instances referring to the old default.realm
need to be closed. Since those instances still hold a file descriptor to it, and the newly opened Realm instances after copying will hold a different file descriptor and Realm still think they are them same Realm since the path is exactly the same. This is a situation Realm cannot handle, and some strange things could happen.
You can call Realm.deleteRealm()
to delete the old default.realm
first. That API will throw if there is any other Realm instance to the realm file which is going to be deleted opened.
Upvotes: 4