Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Realm - Share Database between Apps

So I have a application that is comprised of 3 APK/Apps. How do I share the database between apps? I am assuming the reason it is currently not visible between the apps is because they are passing in different contexts.

Thanks

like image 324
Alan Avatar asked Feb 19 '26 02:02

Alan


1 Answers

Christian from Realm here. Currently what you are asking is really not feasible. As others have pointed out there is really only two approaches.

1) Expose a ContentProvider. However that require you to map RealmResults to a Cursor which is not a trivial effort. We are planning on exposing a RealmCursor down the line, but other things have had priority so we havn't looked at the details yet.

2) Put the Realm database in a shared location and let the apps read from there. This sounds like an easy approach, but unfortunately Realm doesn't support multiple processes yet (which would be required for multiple apps to have the same Realm file open at the same time). So right now you would have to implement a locking scheme in your apps so they can decide who can open the file.

So right now, the the answer is: You sorta can, but it require a lot of hacks, so is not really recommended. On the positive side, we are aware of this and at least multiprocess support are actively being worked on atm.

like image 119
Christian Melchior Avatar answered Feb 21 '26 14:02

Christian Melchior



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!