- iOS/Objective-C 元类和类别
- objective-c - -1001 错误,当 NSURLSession 通过 httpproxy 和/etc/hosts
- java - 使用网络类获取 url 地址
- ios - 推送通知中不播放声音
在 ORMLite 文档中 it is recommended为每个 Activity 创建 OrmLiteSqliteOpenHelper
。由于获取助手只需要一个 Context
对象,为什么不为整个 Application
对象创建一次数据库助手?这将开启使用 Dagger(或其他注入(inject)框架)将数据库助手注入(inject)到需要它的类中的可能性。
有什么理由不创建一个应用程序范围的数据库助手?让每个 Activity 都有自己的数据库助手是否更可取?我可以想象这会使助手的缓存大小保持较小,因为缓存仅包含与其 Activity 相关的对象。
最佳答案
In the ORMLite documentation it is recommended to create the OrmLiteSqliteOpenHelper for every activity.
这不应该暗示您需要为每个 Activity 提供一个单独的助手实例。您当然可以/应该在整个应用程序中共享帮助器。
引用文档:
We recommend using the OpenHelperManager to monitor the usage of the helper – it will create it on the first access, track each time a part of your code is using it, and then it will close the last time the helper is released.
OpenHelperManager
创建和管理助手单例。
如果您向我指出文档中指出每个 Activity 需要不同的点,我会调整它们?
关于android - 为什么不将 OrmLiteSqliteOpenHelper 绑定(bind)到应用程序而不是 Activity ?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20635605/
我是一名优秀的程序员,十分优秀!