我们是否应该经常在android中与数据库存储进行交互? [英] Should we interact with a db storage often in android?

查看:113
本文介绍了我们是否应该经常在android中与数据库存储进行交互?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

与数据库存储进行交互时,Android的性能是否会降低?
从数据库加载对象并传递它们或经常访问数据库以获取对象是否更好?
我在想,是否由于每次都从结果集中实例化对象而导致访问数据库的开销更大.

Is performance in android degrading when interacting with a database storage often?
Is it better to load objects from DB and pass them around or access database frequently to get the objects?
I was thinking if the accessing the DB had more overhead due to instantiating objects from the result set each time.

推荐答案

我正在考虑由于每次都从结果集中实例化对象而导致访问数据库的开销更大.

I was thinking if the accessing the DB had more overhead due to instantiating objects from the result set each time.

是的,这就是为什么,如果您担心性能,则不应使用ORM工具实例化对象.

Yes, it does, which is why if you are worried about performance, you should not use ORM tools to instantiate objects.

经常与数据库存储进行交互时,Android的性能会降低吗?

Is performance in android degrading when interacting with a database storage often?

可能...您正在从磁盘读取数据,这比内存中的存储要慢(提示,

Probably... you are reading from disk, which is slower than in-memory storage (which, hint, SQLite can do)

从DB加载对象并传递它们或经常访问数据库以获取对象是否更好?

Is it better to load objects from DB and pass them around or access database frequently to get the objects?

取决于在什么上下文中您需要实际的类对象.如果将数据存储在数据库中,则仅应在需要时查询该数据,将其加载到对象中,然后执行任何计算逻辑并保存.至少,这是我对此事的看法.您基本上不需要在活动之间序列化任何对象,主要是因为如果在一个活动中更新对象,将其传递给另一个活动,然后别忘了将其保存回数据库,则可能会丢失状态.

Depends in what context you need actual class objects. If you store data in a database, then you should only query for that data when you need it, load it into an object, then do whatever calculation logic and save it. At least, that is my opinion on the matter. You shouldn't need to be serializing any objects between Activities primarily because you could lose state if you update an object in one Activity, pass it to another, then don't / forget to save it back to the database.

这篇关于我们是否应该经常在android中与数据库存储进行交互?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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