Android开发字符串数组资源太大,导致Android App崩溃! [英] Android Development String Array Resource too big, crashing Android App!

查看:60
本文介绍了Android开发字符串数组资源太大,导致Android App崩溃!的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个包含大约1000种药物名称的字符串数组资源

I have a String Array Resource that has about 1000 drug names

<string-array name="index">
<item>Aspirin</item>
  <item>Levitra</item>
  ....
</string-array>

我试图将此字符串数组加载到活动中的String []中.使用Google的Java文档提供的相同语法(可在此处找到). http://developer.android.com/guide/topics/resources/string-resource.html#StringArray

I tried to load this string array into a String[] inside an activity. Using the same syntax provided by Google's java documentation found here. http://developer.android.com/guide/topics/resources/string-resource.html#StringArray

Resources res = getResources();
String[] drugs = res.getStringArray(R.array.index);

似乎我的字符串数组有太多记录,并且导致我的应用程序崩溃(堆栈溢出?)当我将字符串数组资源减少到约506条记录时,该应用程序再次工作,但甚至增加了1个元素在字符串数组中会使应用程序崩溃.

It appears my string-array has too many records and its causing my App to crash (stack-overflow?) When I reduce the string-array resource to about 506 records, the app works again, but adding even 1 more element in the string-array would crash the app.

我该怎么办?我想对逻辑进行编码以对列表进行过滤并执行其他操作.我的应用程序中没有SQL数据库,因此无法在数据库中进行处理.有没有办法遍历字符串数组资源而不将其加载到String []中?我注意到资源是一个指针.还是有其他可行的数据结构或方法?

What should I do? I want to code logic to filter and do other things to the list. I do not have a SQL db in the app so I can't do the processing in the DB. Is there a way to iterate through the string-array resource without loading it into a String []? I notice the resource is a pointer. Or is there an alternative data structure or approach that would work?

谢谢

推荐答案

您是否有不想使用SQL数据库的原因?我强烈建议您建立一个SQLite数据库.字符串数组并非设计用于此大小的数据.您的应用程序运行缓慢,并且会占用大量内存.

Is there a reason why you don't want to use an SQL database? I would strongly recommend setting up an SQLite database. String arrays were not designed for data of this size. Your app will be slow, and it will consume a lot of memory.

我唯一想到的替代方法是使用单个字符串并具有一个字符串ID值数组-应该可以.

The only alternative I could think of would be to use individual strings and have an array of string ID values - that should work.

这篇关于Android开发字符串数组资源太大,导致Android App崩溃!的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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