何时/如何创建/销毁会议室数据库 [英] When / How to Create / Destroy Room Database

查看:71
本文介绍了何时/如何创建/销毁会议室数据库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道是否有人可以指出我的文档来/澄清何时创建或销毁会议室数据库实例.另外,您将如何有效地打开/关闭它?

I was wondering if someone could either point me to documentation to / clarify when to create or destroy a room database instance. Also how you would effectively open / close it ?

如果我有一个通过匕首注入到演示者的 RoomDatabase 对象,那太酷了,然后我可以访问各种Daos吗?我担心对象会挥之不去并占用内存.

If I have a RoomDatabase object that gets injected via dagger to a presenter is that cool and then I just access various Daos? I'm worried about having the object lingering and taking up memory.

推荐答案

您可以注入 DataManager Singleton类,而不是将 RoomDatabase 插入演示者.

Instead of Injecting the RoomDatabase into your presenter you could Inject a DataManager Singleton class.

DataManager 可以将 WeakReferences 保留到 DAO s中.根据您尝试访问数据的时间,首先检查内存中是否有数据,然后将其传递给演示者,如果没有,则可以懒惰地访问 RoomDB 将数据加载到内存中,然后继续给演示者.

This DataManager can hold your WeakReferences to your DAOs . Based on when you try to access the data, first check if you have it in memory pass it on to the presenter, if not you can then Lazily access the RoomDB to load data into memory and then pass on to the presenter.

通过这种方式,可以访问/管理您的数据的单一真相来源.

In this way, there is a Single Source of Truth that accesses/manages your data.

这篇关于何时/如何创建/销毁会议室数据库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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