Android - How to store Address to DB

2019-08-06 22:01发布

Looking to store android.location.Address to a SQLite database. I am using ORMLite to persist my objects. ORMLite can persist Serializable items (as a BLOB I believe) but I think the only way to get something Serializable from an Address is to write it into a Parcel. Then I took a look at Parcel here: http://developer.android.com/reference/android/os/Parcel.html and it says it should not be used for general purpose Serialization mechanism. So I am just wondering what the best practice for doing this would be. I do not want to store the Address in contacts, strictly in my SQLite database. I am currently doing this with my own Address class (very simple) but would prefer to use the built in Android class for this.

thanks

1条回答
Melony?
2楼-- · 2019-08-06 22:46

The answer from the user list was to define a companion object that will be stored to the database and do the translation to/from the android.location.Address object by hand -- unfortunately. This will allow you to manager the storing of the various Address fields to the database without worrying about forwards and backwards compatibility with other Android versions.

Here's the discussion on the ormlite-user mailing list.

查看更多
登录 后发表回答