我只能在Application中调用一次Realm.getInstance()吗? [英] Can I only call Realm.getInstance() once in Application?

查看:72
本文介绍了我只能在Application中调用一次Realm.getInstance()吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在玩Realm,我总是发现在Activity创建期间调用了Realm.getInstance(),并在Activity destroy中关闭了实例.我是否知道在关闭应用程序之前一直保持仅创建和打开一个实例是否有任何副作用?

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?

推荐答案

没有应用程序onDestroy. Realm在内部进行必要的缓存,因此可以安全地多次调用Realm.getInstance()/close().

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.

尝试进行自己的缓存不会使效率更高.您可以在此处阅读有关如何控制Realm实例生命周期的信息:

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 -实例

这篇关于我只能在Application中调用一次Realm.getInstance()吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆