Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android Development String Array Resource too big, crashing Android App!

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

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

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);

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.

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?

Thanks,

like image 626
Mashsensor Avatar asked Apr 28 '26 23:04

Mashsensor


1 Answers

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.

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

like image 172
EboMike Avatar answered May 01 '26 12:05

EboMike



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!