简体   繁体   English

在Android上的数据库中存储事件的最佳方法是什么?

[英]What's the best way to store events in a database on android?

I've been struggling with this problem so here is my first SO post. 我一直在努力解决这个问题,所以这是我的第一篇SO帖子。

I'm writing an Android app that needs to store events with seconds precision. 我正在编写一个需要以秒为单位存储事件的Android应用。 After this data gets collected for a while, I'd like to be able to display it in a graph where the user can view this event history over time. 收集这些数据一段时间后,我希望能够在图形中显示它,以便用户可以随时间查看此事件历史记录。 This makes me think of using a sqlite database in android with a table with columns: 这让我想到了在android中使用带列表的sqlite数据库:

| eventname | timestamp |

Then I can get the number of each event type by counting rows in the table, and show the graph based on Last Day, Last Week, Last Month, etc. I've never worked with databases before though, so I'm not sure if this is a good approach to what I assume is a common problem. 然后,我可以通过对表中的行进行计数来获取每种事件类型的数量,并根据“上一天”,“上周”,“上个月”等显示图表。不过,我之前从未使用过数据库,因此不确定如果这是解决我认为是常见问题的好方法。

Any help is appreciated! 任何帮助表示赞赏!

For me the main criteria if to use database or no, it would be: - persistance - if you want to keep the data for long period and to return to them ex. 对我而言,使用或不使用数据库的主要标准是:-持久性-如果您想长时间保留数据并返回给他们。 after a week or a month - how complicated the structure is (for simplier, perhaps just an xml file would be easier, or txt file etc.)? 一个星期或一个月后-结构有多复杂(为简单起见,也许只是一个xml文件会更容易,或者txt文件等)?

You don't write too much so it's difficult to advise. 你写的东西不多,所以很难建议。 I believe you will have to read a lot if you have never worked with databases earlier. 我相信,如果您以前从未使用过数据库,则必须阅读很多东西。

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

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