Android在SQLite中存储一个Parcelable对象 [英] Android Store a Parcelable Object in SQLite

查看:142
本文介绍了Android在SQLite中存储一个Parcelable对象的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要在Sqlite中存储对象内容. 我想知道哪种方法是对对象进行序列化或对Parcelable进行处理的最佳方法.

I need to store an object content in Sqlite. I was wondering which was the best way to do it with a serialization of the object or with Parcelable.

是否可以将其存储为Parcelable?我该怎么办?

Is it possible to store it as Parcelable? How can I do it?

推荐答案

欢迎您将您的对象转换为某种可持久的数据结构(XML,JSON,Serializable)并将其填充到某些数据库列中.请记住,您仍然需要处理兼容性问题(例如,应用的版本2更改了一个类,现在需要同时处理版本1和版本2结构).还请记住,沿这条路线,您将失去许多数据库功能(例如,查询对象中的某些内容).

You are welcome to convert your object into some sort of persistable data structure (XML, JSON, Serializable) and stuff it in some database column. Bear in mind that you will still need to deal with compatibility issues (e.g., Version 2 of your app changes a class, which now needs to deal with both Version 1 and Version 2 structures). Also bear in mind that, going this route, you lose a lot of database capabilities (e.g., querying on something in the object).

如果不需要SQLite,也欢迎您尝试使用对象数据库或CouchDb,或将持久性数据结构存储到文件中.

You are also welcome to experiment with object databases, or CouchDb, or storing your persistable data structure to a file, if SQLite is not a requirement.

最不能肯定的是将Parcelable倒入Parcel并尝试存储Parcel. Parcel仅用于IPC,不能持久保存.这是ParcelableSerializable快的原因之一.

What most certainly will not work reliably is to pour the Parcelable into a Parcel and try storing the Parcel. A Parcel is meant for IPC use only and is not designed to be persisted. This is one of the reasons why Parcelable is faster than Serializable.

这篇关于Android在SQLite中存储一个Parcelable对象的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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