Realm.init() in libraries and ContentProvider


In the library example you can find this comment The app is responsible for calling Realm.init(Context).

I tried to find some reason that mentions any downsights of calling Realm.init() in the library instead of the app.

So my first question is: Are there any downsights of calling Realm.init() inside a library?

For my second question I found this GitHub Issue where they talk about Realm.init() in ContentProvider. The only thing that was mentioned that I can’t test right now is from @ChristianMelchior that this approach doesn’t work well with multiprocessing.

So are there any other reasons for not calling Realm.init() in a ContentProvider?


I can see one clear downside:

  • Realm is thread safe: any changes on a realm will be available only the thread where it initialised. You can open multiple ones but then you will have synchronisation issues.

Otherwise, i believe you can use it in a library.


Yes I know that its thread safe but isn’t that just about Realm.getInstance() and not about Realm.init()?