传递大型包裹或传递ID并查询db效率更高吗? [英] Is it more efficient to pass large parcelable or pass id and query db?

查看:74
本文介绍了传递大型包裹或传递ID并查询db效率更高吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

就像在锡罐上说的那样.我有一个体面的对象,它由大约20个变量组成,其中一些变量本身就是android对象(Calendar,Uri).任意数量的这些对象存储在数据库中.

Just like it says on the tin. I have a decent sized object, consisting of about 20 variables, some of which are themselves android objects (Calendar, Uri). An arbitrary number of these objects are stored in a database.

我需要故意将单个对象传递给广播接收器.创建意图时,我已经将整个对象作为局部变量,并且不会查询数据库.将整个对象作为包裹传递,或者传递数据库ID并通过我的onReceive方法从数据库中提取对象,效率更高?

I need to pass an individual object by intent to a broadcast receiver. When I create the intent I already have the entire object as a local variable and would not be querying the database. Is it more efficient to pass the entire object as a parcel, or to pass the database id and pull the object from the db in my onReceive method?

我怀疑是前者,但是直到昨天我才做后者,因为我懒得实现包裹.我做到了,但是现在我第二次猜测自己.

I suspect the former, but until yesterday I was doing the latter because I was too lazy to implement parcelable. I did, but now I'm second guessing myself.

P.S.我不是CS专业.在这种情况下,我定义了最有效的方法,即对用户体验的影响最小.

P.S. I'm no CS major. In this case I define most efficient to mean least impact on user experience.

推荐答案

如果所讨论的对象很小(小于1MB),则使用Parcelable路由应该更有效.基本上,您避免了磁盘I/O(以及在广播触发时尝试在后台线程上执行此操作所带来的复杂性).

If the object in question is small (under 1MB), then going the Parcelable route should be more efficient. Basically, you avoid the disk I/O (and the accompanying complexity of trying to do that on a background thread when triggered by a broadcast).

这篇关于传递大型包裹或传递ID并查询db效率更高吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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