简体   繁体   English

在Android应用程序上存储“收藏夹”等数据的最佳方法是什么?

[英]what is the best way to store data such as 'Favorites' on an Android-app?

I am developing an Android application where you should be able to browse restaurants. 我正在开发一个Android应用程序,您应该可以在其中浏览餐厅。

Im retrieving the information about the restaurants from a service, they are not stored locally on the device. 从服务中检索有关餐厅的信息时,餐厅的信息未本地存储在设备上。 But I want to allow the user to add a restaurant to his/her favorites. 但我想允许用户将餐厅添加到他/她的收藏夹中。

What is the "best" way to store that kind of info on the device? 在设备上存储此类信息的“最佳”方法是什么? Should I use Shared Preferences or Sqlite db? 我应该使用共享首选项还是Sqlite数据库? Or any other suggestions? 或其他建议?

SqLite is probably the best way to go. SqLite可能是最好的选择。 It will allow you to structure the information in useful ways, whereas SharedPreferences is more of a Key-Value affair. 它将使您能够以有用的方式来构造信息,而SharedPreferences更像是键-值事务。 That might be fine if you only need to store a set of strings, but it will be a pain if you ever decide you need to store additional information with a favorite, such as ordering, type, or date. 如果您只需要存储一组字符串,那可能会很好,但是如果您决定需要存储带有收藏夹的其他信息(例如订购,类型或日期),那将很痛苦。

If you use SqLite, you can easily add columns. 如果使用SqLite,则可以轻松添加列。

如果您知道SQL,请与SQLite数据库一起使用;如果您不与SharedPreferences一起使用,则可以使用。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM