Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
352 views
in Technique[技术] by (71.8m points)

java - 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

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...