Android的 - 公平存储的数据在本地,XML / JSON或SQLite的呢? [英] Android - Storing fair amounts of data locally, xml/json or SQLite?

查看:217
本文介绍了Android的 - 公平存储的数据在本地,XML / JSON或SQLite的呢?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

长话短说:我正在重构我的一个老的Andr​​oid项目。 previously,它使用序列化,这是十分缓慢,而且从我读什么,一般一个pretty糟糕的主意Android应用。我正在寻找另一种方式来坚持这两个用户特定的数据,以及和只读应用程序的数据。

Long story short: I'm working on refactoring an old Android project of mine. Previously, it was using serialization, which was painfully slow and, from what I'm reading, a pretty lousy idea in general for Android apps. I'm looking for another way to persist both user-specific data as well and read-only data for the application.

有将是双方的数据一个很好的协议,我不知道是否有一个好的方式来存储它。基本上,应用程序是一个小的RPG。有一些地图被重新psented作为瓷砖的二维数组$ P $的。每个区块都会有一些属性,一些简单的原语或枚举,其他额外的对象,如事件,这也将潜在地包含各种物体,等有了400瓦,仅一个20×20的地图,有数据存储的不少。除了存储数据,就需要存储大量用户特定的数据,比如哪些瓷砖已访问,这事件已成功运行的等。

There is going to be a good deal of data on both sides and I'm not sure if there's a "good" way to store it. Basically, the app is a small RPG. There are a number of "maps" that are represented as 2D arrays of Tiles. Each Tile will have a number of attributes, some simple primitives or enums, others additional objects, such as Events, which will also potentially contain various objects, etc. With 400 Tiles in a 20x20 map alone, there's a LOT of data to store. In addition to storing that data, it would need to store a lot of user-specific data, such as which Tiles have been visited, which Events have been successfully run, etc.

我已经研究了这个保存数据的方法,我只是似乎无法定居的东西。我猜想它归结为XML或JSON VS SQLite的。 XML或JSON将是未来的变化,因为我想中的数据,也就是灵活性,这是好的方面更加灵活,增加新的属性将现有对象,增加新的对象,在有需要时,等SQLite是不容易可塑性因为你必须改变了模式,或者调整查询和索引等,但我还没有真正使用在过去的SQLite,也许有一些功能,可以帮助简化这个过程。不过,我也想对数据的快速随机访问,以避免同时如果能够帮助一切加载到内存中。例如,从一个地图移动到另一个的时候,我宁愿加载只在需要的时候,而不是保存在内存中拥有一切,这就是SQLite的将大放异彩,因为我会能够直接查询数据,而不是下图遍历JSON / XML文件中查找潜在分散的数据,也就是说,我们加载地图,而是包含在事件事件和对象未必是独特的地图,可以很容易地在其他地方在文件或其他文件完全。然而,在SQLite的标准化数据将意味着很多的表,并颇有几分解构/对象重建的。

I've been examining methods of saving this data out and I just can't seem to settle on something. I guess it boils down to XML or JSON vs SQLite. XML or JSON would be more flexible in terms of future changes, which is good as I want flexibility in the data, ie, adding new attributes to existing objects, adding new objects as the need arises, etc. SQLite isn't as easily malleable as you have to change up the schema, perhaps adjust queries and indexes, etc, but I haven't really used SQLite in the past, so maybe there are some features that help to simplify that process. However, I would also like fast random access to data to avoid loading everything into memory at once if it can be helped. For example, when moving from one map to another, I'd much rather load the next map only when needed rather than having everything held in memory, which is where SQLite would shine as I'd be able to directly query the data rather than traversing a JSON/XML file to find potentially scattered data, ie, we load the map, but Events and objects contained in the Events may not be unique to that map and could easily lie elsewhere in the file or in another file entirely. However, normalizing the data in SQLite would mean a lot of tables and quite a bit of deconstructing/reconstructing of objects.

编写用户数据只会发生,所以写性能不是一个大问题。

Writing user data would only occur when the user manually saves the game, so write performance is not a big issue.

我有时不得不过度分析并获得挂了这样的东西的倾向。也许两种情况下必然是错误的,我担心的事情是微不足道的。也许有,我还没有考虑其他情况。我使用Hibernate和考虑类似ORMLite处理很多数据库的基本事实,但是这将需要大量改造的,可能比我还需要其他的选择做多。

I sometimes have a tendency to overanalyze and get hung up on stuff like this. Maybe neither case is necessarily "wrong" and I'm worrying about things that are infinitesimal. Maybe there are other cases that I haven't considered. I've used Hibernate and have considered something like ORMLite to handle a lot of the database nitty-gritty, but that would require a lot of retrofitting, likely much more than what I would need to do for other options.

推荐答案

我建议你使用SQLite。我认为这是最有意义的考虑数据的你想存储量。

I'd suggest you use SQLite. I think it makes the most sense considering the amount of data you're trying to store.

至于你担心它不是那么灵活,我认为这一点。只需使用一个ContentProvider的。 ContentProviders使它pretty容易更新数据库架构和查询,而不影响现有的功能。如果您使用ContentProvider的,你甚至可以同时换出在未来的持久性数据战略,以及使用不同的。

As far as your concerns with it not being as flexible, I would argue that point. Just use a ContentProvider. ContentProviders make it pretty easy to update the db schema and queries without affecting your existing functionality. If you use a ContentProvider, you could even swap out persistent data strategies in the future as well as use different ones simultaneously.

http://developer.android.com/guide/topics/提供商/内容providers.html

这篇关于Android的 - 公平存储的数据在本地,XML / JSON或SQLite的呢?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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