Can I only call Realm.getInstance() once in Application?

痞子三分冷 提交于 2020-01-06 04:21:06

问题


I am toying with Realm and I always find that Realm.getInstance() is called during Activity create and instance closed in Activity destroy. May I know is there any side impact that keep only one instance create and open all the time until the application is closed?


回答1:


There is no Application onDestroy. Realm does the necessary caching internally, so it should be safe to call Realm.getInstance()/close() as many times as you want.

Trying to do your own caching will not make anything more efficient. You can read about how to control the Realm instance life cycles here:

https://realm.io/docs/java/latest/#controlling-the-lifecycle-of-realm-instances https://realm.io/docs/java/latest/#closing-realm-instances



来源:https://stackoverflow.com/questions/37692668/can-i-only-call-realm-getinstance-once-in-application

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!