我是一名学习 android 的 php/mysql 开发人员。我正在创建一个 Android 应用程序,它从我的 php 应用程序接收信息,以创建不同产品的列表视图,这将打开该产品详细信息的 Web 视图。
目前我的 php cms Web 应用程序为 iphone 应用程序输出 xml 列表....(也单独输出 html)。我可以完全控制 php 应用程序,因此如果有更好的方法来输出 Android 应用程序的数据,请告诉我。
我创建了从 Web 读取 xml 并创建列表视图的代码。该列表可以每天刷新,因此不需要每次应用程序启动时都从在线xml中读取数据。
因此,我正在考虑存储本地检索的数据以提高我的应用程序的响应能力。在任何给定时间,最多可能有 500 个产品描述存储在最多 30 个不同的 xml 列表中。我开始开发一个包含大约 30 种产品的 xml 列表。
为了获得最佳性能,我应该将产品信息存储在 sqlLite 数据库中,还是应该将实际的 xml 文件存储在缓存/数据库中或其他一些方法(例如应用程序缓存)中。
我还考虑将数据更新创建为服务,这是一个好主意吗?
I am a php/mysql developer learning android. I am creating an android app that receives info from my php app to create list views of different products which will open a web view of that product's detail.
Currently my php cms web application outputs xml lists for an iphone app.... (also, separately outputs html). I have full control of the php app so if there is a better way to output the data for the android app please let me know.
I have created code that reads the xml from the web and creates the list view. The list can be refreshed daily, so the data does not need to be read from the online xml every time the app starts.
So I was thinking to store the data retrieved locally to improve my apps responsiveness. there may be up to 500 product descriptions to be stored at any given time in up to 30 different xml lists. I am starting development with one xml list with about 30 products.
For best performance should i store the product info in a sqlLite db or should i store the actual xml file in the cache/db or some other method like application cache.
I also was think to create the update of the data as a service, would this be a good idea?
发布评论
评论(2)
存储数据最有效的方式是 RAM。但如果你想缓存它,那么最有效的方法就是数据库。
我建议您将数据存储在 sqlite android 数据库中。
您还可以考虑压缩 xml 以加快网络传输速度,并通过 java.util.zip 包类进行解压缩。您甚至可以考虑使用数据输入/输出流,使用更简单的格式来传输数据,比 xml 更简洁。
(我在我的应用程序中这样做,效果很好)
以下是有关数据输入/输出流方法的一些详细信息:
这种技术的优点是可以节省带宽,因为只有数据,没有 xml 带来的详细装饰。您应该阅读有关 java 规范的内容,以了解如何在数据输出流中写入 double、int、string。但使用两种语言来获取正确的数据可能很困难。
如果php不能以合适的方式保存格式,使用xml,会简单得多。首先尝试使用纯 xml,然后尝试使用 zip、tarball 或 xml 文件。
但这一切都是关于网络连接期间的速度增益。
您要做的第二部分是将列表的每一行存储在 SQL 表中。然后,您可以使用列表视图的 CursorAdapter 快速检索它(它破坏了迷人的 MVC 模型,但速度相当快!)。
The most efficient way to store data is RAM. But if you want to cache it, then the most efficient way is Database.
I recommend you store your data in sqlite android database.
You could also consider zipping you xml for faster network transfer and unzipping through java.util.zip package classes. You could even consider a simpler format for transmitting data, less verbose than xml, using a datainput/outputstream.
(I do that in of my apps and it works great)
Here are some details on data input / output stream method :
The advantage of this technique is that you save bandwith as there is only data and no verbose decoration due to xml. You should read about java specs to understand how double, int, strings are written in data output stream. But it can be hard using two languages to get the data right.
If php can't save format in a suitable way, use xml, it will be much simpler. First try with just plain xml, then give a try using a zip or tarball or xml file.
But all this is about speed gain during network connection.
The second part of what you have to do is to store each row of your list in a SQL table. Then you can retrieve it pretty fast using a CursorAdapter for your list view (it breaks the charming MVC model but it is quite fast !).
对此感到抱歉,但作为评论写起来太长了。这并不是要回答你的问题,因为在我看来,Stéphane 回答得很好。最好的解决方案确实是将数据存储在 sqlite 数据库中。然后您需要创建用作数据、数据库和应用程序之间的连接的类。我不想把这里所说的归功于我(我也投了赞成票)。
我关心其他建议(使用低级原始流进行数据操作,该答案的列表步骤)。我强烈建议您避免创建自己的专有协议。它是这样的:
每当我需要处理未知的、晦涩的和任意的数据块序列时,它都会让我哭泣。记住为什么我们不应该使用未知格式总是好的:
最后,如果目的是避免 XML 典型的冗长,无论出于何种原因,您都有多种选择。现在我可以想到 CSV,但我不是数据存储方面的专家,所以如果您对它不满意,我相信您可以找到很好的替代品,并提供大量现成的 API。
祝你好运!
Sorry about this, but it became too long to write as a comment. This is not intended to be an answer to your question, because in my opinion Stéphane answered very well. The best solution is indeed to store the data in an sqlite database. Then you need to create the class to be used as a connection between the data, the database and the app. I don't want to take credit for what is said here already (I, too, voted it up).
I'm concerned with the other suggestion (use of low level raw streams for data manipulation, the list steps on that answer). I strongly recommend you to avoid creating your own proprietary protocol. It goes like this:
It makes me cry whenever I need to deal with unknown, obscure and arbitrary sequence of data blobs. It's always good to remember why we should not use unknown formats:
Finally, if the purpose is to avoid the typical verbosity of XML, for whatever reasons, you have several options. Right now I can think of CSV, but I'm no expert in data storage, so if you're not confortable with it, I'm sure you can find good alternatives with plenty of ready to use APIs.
Good luck!