简体   繁体   English

在Android中从CSV文件加载大量数据的最有效方法是什么?

[英]What is most efficient way for loading big amount of data from CSV file in Android?

I have 15MB csv file (350 000 lines). 我有15MB的CSV文件(35万行)。 I have problem with loading this data. 我在加载此数据时遇到问题。 I have tried: 我努力了:

1) Loading file data to memory: quite fast (about 7 seconds), but I'm receiving OutOfMemory error and OS closes my app. 1)将文件数据加载到内存:相当快(大约7秒),但是我收到OutOfMemory错误,并且操作系统关闭了我的应用程序。 Even without this error, it's not perfect solution to load data for 7 seconds during each application start. 即使没有此错误,在每次启动应用程序时加载7秒钟的数据也不是完美的解决方案。

2) Loading to SQLite DB: would be perfect(only one load is required), but loading process takes more than 1 minute ( I'm using db.begintransaction/endtransaction to speed up process). 2)加载到SQLite DB:会很完美(只需要加载一次),但是加载过程需要1分钟以上的时间(我使用db.begintransaction / endtransaction来加快过程)。

3) I can't ship app with preloaded data, because this CSV contains feeds, which should be updated periodically. 3)我无法为应用提供预加载的数据,因为此CSV包含供稿,应定期对其进行更新。

I was testing app with Samsung S3. 我正在用Samsung S3测试应用程序。 Not the slowest smartphone. 不是最慢的智能手机。

------ Update ------更新

Possibly there are special tools for bulk load of CSV data to database?? 可能有用于将CSV数据批量加载到数据库的特殊工具?

I can't ship app with preloaded data, because this CSV contains feeds, which should be updated periodically. 我无法向应用程序发送预加载的数据,因为此CSV包含供稿,应定期对其进行更新。

As I understand you need to do this background operation periodically using service and sync data with server and at the same time insert/update received records to SQLite database. 据我了解,您需要定期使用服务执行此后台操作,并与服务器同步数据,同时将接收到的记录插入/更新到SQLite数据库。

First time when database is empty then you can give progress bar with appropriate message that data is being retrieved and copied into local database. 第一次当数据库为空时,您可以在进度栏上显示适当的消息,指示正在检索数据并将其复制到本地数据库中。 Once this done then display data which has been received. 完成此操作后,将显示已接收的数据。

Later, on you can use SyncAdapter to keep sync your application database with server or run a service periodically. 稍后,您可以使用SyncAdapter保持应用程序数据库与服务器同步或定期运行服务。

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

相关问题 以最有效的方式从数据库中获取大量数据 - Getting a huge amount of data from database in the most efficient way Java-读取具有各种数据类型的CSV文件的最有效方法 - Java - Most efficient way to read in a CSV file with various data types 在Android中重复写入XML文件的最有效方法是什么? - What is the most efficient way of repeatedly writing to an XML file in Android? 按需将数据从文件加载到集合的最有效方法是什么? - What's the most efficient way to load data from a file to a collection on-demand? 使用RandomAccessFile在具有大量数据的文件中插入标头的最有效方法 - Most efficient way to insert a header in a file with large amount of data using RandomAccessFile MySQL,从已解析文件加载数据的最有效方法 - MySQL, Most efficient Way to Load Data from a parsed file 从文件读取字符的最有效方法? - Most efficient way to read characters from a file? 处理大量HttpRequest的最有效方法 - Most efficient way to deal with Large Amount of HttpRequests 合并两个大列表的最有效方法 - Most efficient way of combining two big lists 将 memory 中的大量数据写入文件的最快方法是什么? - What is the fastest way to write a large amount of data from memory to a file?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM