开始与大型意图演员的活动意图、演员

2023-09-07 13:44:06 作者:孤心无意

我开始用可序列化额外的活动。这额外的包含自定义对象拿着一堆类型,主要是字符串列表。我读从我的项目的资产文件夹中的数据,并与GSON解析它(该数据是JSON)。该文件是〜108KB的大小

I am starting an activity with a Serializeable extra. This extra contains a List of a custom object holding a bunch of types, mostly Strings. I read in the data from the assets folder of my project, and parse it with GSON(the data is JSON). This file is ~108KB in size.

有关我的应用程序的整个生命和全部数据被传来传去的意图临时演员。这是非常方便的,因为我不担心重新加载从资产数据的文件夹再次,应用程序停机的恢复是一切的照顾,而我也不需要管理SQLite数据库(版本管理,查询等)。

For the life of my application, all data is being passed around as intent extras. This is very convenient as i don't have to worry about re-loading the data from the assets folder again, app shutdown recovery is all taken care of, and i don't need to manage an SQLite database(versioning, queries, etc).

问题: 我发现周围路过这些群众演员会非常慢(开始活动的所有数据将可能为1.5秒或以上)。我似乎无法显示任何加载对话框或者,因为它似乎是一个阻塞调用启动一项活动,并附加额外的。

Problem: I find that passing these extras around can become quite slow(starting an activity with ALL the data takes maybe 1.5 seconds or more). I can't seem to show any "loading" dialog either, as it seems to be a blocking call to start an activity and attach extras.

问题(S): 我应避免周围像我所描述过这些演员?是一个使用SQLite数据库与此数据进行交互的最佳选择?什么样的建议,你必须避免很多SQLite数据库/全局静态变量大惊小怪的访问我的应用程序的数据?

Question(s): Should I avoid passing these extras around like I have described? Is the best option using an SQLite database to interact with this data? What suggestions do you have to avoid a lot of the fuss of SQLite databases/global static variables for accessing my application's data?

拍我的JSON数据到数据模型类,并通过他们作为演员的意图很容易和漂亮的(貌似),我不想放弃!

Slapping my JSON data into data model classes and passing them as intent extras is easy and nice(seemingly), and i don't want to give it up!

推荐答案

我有同样的问题,跟着你已经描绘的解决方案。我用一个SQLite数据库来存储信息,则只能通过唯一的ID作为额外的意图,并显示在被叫活动正在加​​载...进度对话框,而我访问的数据库。

I had the same problem and followed the solution you already depicted. I used an SQLite DB to store the information, then passed only unique ids as intent extra and displayed a "loading..." progress dialog on the called activity while I accessed the DB.

Prolly使用SQLite是要走的路。

Prolly using SQLite is the way to go.