-
Notifications
You must be signed in to change notification settings - Fork 1.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Change Realm file without restarting application #2153
Comments
As long as you have closed all Realm instances you are free to swap the file out, or create a new RealmConfiguration and use that.
|
wow, that was fast, i will try and return here to say ok? thank you so much |
not worked properly, i have a Constants method to set the RealmConfiguration(im in migration number 4) the method:
and im using this after the file swap:
but i still need to restart the application to see the changes, everyquery show as empty, after the restart, work perfectly maybe im doing something wrong, i will try another approach |
Just changing the file, won't refresh the UI. You still need to open a new Realm instance, load all the data again and refresh the UI |
@defaultbr Did you solve the problem? |
Sorrryy, i forgot to post, not really, was receiving the same problem so i kept the restart app method, right now im doing a code cleanup and will try again |
@defaultbr By the way, will be Realm file on your Google drive be overwritten? I mean, if two devices are accessing the same Realm file, it is not hard to image that the app will be messed up. Realm is using |
Hi @defaultbr I assume you found a way to make this work. Feel free to reopen if that is not the case. |
Sorry for the late post, i was out for a while and now i had to "destroy" my app and restart everything from zero!! and i stopped again at this part..... i cant close Realm instance im using this in my MainActivity:
but how to close instance? its impossible since its used anywhere in other files/classes/methods using the Realm.getDefaultInstance(); i`ve tried this:
but for both say FALSE, WHY? and now if i use the onBackPressed to close the mainActivity and try to open the app again, it give me a Exception:
so probrably i was more secure using this in each place i was using the database:
anyway, is there any method like:
im lost in the cycle of realm, why im getting this exception when i use onBackPressed? |
@defaultbr Sorry, but there is no Using |
@beeender thanks the explanation, so which way will be the best? since i need to call getInstance in MANY different activities and sometimes inside asynctask? |
Is there a way, (for debugging purposes) to get access to the number of open realms? I am having the same problem as @defaultbr trying to replace the Realm file without restarting the app. The other option I have thought of is to open a open the replaced realm on another path and then something like this
This method works and allows me to replace the database content without restarting, but doing deep copies of the entire database is a very expensive operation. Is there any better way? |
To add to this. For me, it was just about that I was having a Realm open. It was very helpful to set a breakpoint i Realm.getDefaultInstance and in realm.close just to identify where the problem was. |
I had so many places where i was using last week i took the time and patience to clear the code and use the onCreate, onDestroy to build the this turned the thing so much easier!! now i can swap everything easy, change database, do backup, restore no matter what 💃 and my question to beeender is pointless, now i know much more about how realm works thank you all guys =) TIP for future noobs like me: use Application level to set the Configuration, and for each Activity/Async/etc.. that you NEED to use the realm, use the onCreate and onDestroy, and for async, initiate it at the doInBackGround and close before the return |
What would be the correct approach to do this (change the realm file) using React Native? |
@sorinns Maybe you question is better asked at https://github.com/realm/realm-js but you should store your Realm instance in the local state and use |
Hi, im currently using GoogleDrive to backup the Realm database file
and when i need to restore, i just delete the old file and than put the new one from GoogleDrive in its place, but to work i need to restart the application.
so im looking a way to avoid the app restart (not a major problem of course)
is there anyway like: "Realm.disconnect()" and after returning the new file, "Realm.connect()"
The text was updated successfully, but these errors were encountered: