Android:长时间存储大量传感器数据的最佳方式 [英] Android: Best way to store large amount of sensor datas over long time

查看:82
本文介绍了Android:长时间存储大量传感器数据的最佳方式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是 Android 开发的新手,我有一个关于 How-To 的一般性问题:

I'm fairly new to Android-Development and I got a general question about How-To:

我的应用从 Step-Detector 获取 Sensor-Data(检测到的步数被累加).现在我需要存储这些步骤(这将是很多数据).

这些步骤应该像这样存储:
如果今天
步数按小时存储.
其他
步数按天存储

SharedPreferences 不属于这种情况,因为它只存储 KeyValues.

My App gets Sensor-Data from Step-Detector (Detected steps gets added up). Now I need to store those Steps (which will be a lot of Data).

The steps should be stored like this:
If Todays
steps are stored on per Hour basis.
Else
steps are stored on per Day basis

SharedPreferences falls out of this as it only stores KeyValues.

但是 SQLite 可以处理这个吗?或者还有其他方法吗?未来的功能可能是将这些数据与服​​务器同步.我的意思是这最终可能会包含数千个条目,并且该应用程序还将支持需要以类似方式存储的其他大型数据集.

But can SQLite handle this? Or is there any other way? A future feature could be to sync those data with a Server. I mean this could end up in thousands of Entries, and the app will also support other large data sets which need to get stored in similar way.

推荐答案

尝试使用 Realm noSql 数据库.关键是,您可以将整个数据库作为单独的文件保存在 SD 卡上,以便日后处理.它是原生的,在处理大量数据时工作速度非常快.您可以稍后处理所有读数 - 打开数据库,转换读数(可能插入旧值以缩小数据大小),然后将其上传到云并删除数据库文件.但是,无论如何,数据库只是实现细节,请考虑抽象出所有操作,以便稍后替换 db.据我所知,sqLite 将所有表存储在一个文件中,因此您将需要日期列,所有记录都将存储在单个表中.Realm 可以更灵活地完成这项任务.

Try using Realm noSql database for it. The point is, you can save entire database on sd card as separate file for each day and process it later. It is native and work very fast with large amount of data. You can process all your readings later on - open database, transform readings (perhaps interpolate values for older to shring data in size) and then upload it to the cloud and delete database file. But, anyways, a database is just implementation details, consider abstracting out all your operations so you can replace db later on. As far as I know, sqLite stores all tables in a single file, so you will need column for a date and all records will be stored in single table. Realm is more flexible for this task.

这篇关于Android:长时间存储大量传感器数据的最佳方式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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