Reputation: 494
I am currently learning android development by following a tutorial. I think I learned enough to create my first very simple app. Indeed I have an idea but I need your help for something. For this application I need between 500 and 5000 strings to be included in my app. By following the tutorial and doing some research, I found three different ways for string storage, but I don't know which one I should use for 5000 strings.
The first is by putting the strings in the strings.xml file in the resources but it would be very long.
The second is using a .txt file and read it
The last one would be the use of a database, but I don't know if it worth it for only strings.
So what do you think I should use and if you know another way to do it, even if it isn't the best solution, could you let me know please.
Upvotes: 1
Views: 102
Reputation: 17
The best way to store the large amount of the string is the database. The advantages of the database are:
Separation of the strings is easy.
The database is faster while loading the string.
Upvotes: 1
Reputation: 4375
1. Strings.xml
Pros: Go for it if want your application will be localized in different languages. It will be easy for you to translate your string in different languages and use it with just there id references
Cons: To hard to reference/handle 500 strings with their id (not recommended)
In strings.xml
<string-array name="large_string_data">
<item>String 1</item>
<item>String 2</item>
<item>String 3</item>
<item>String 4</item>
<item>String 5</item>
...
<item>String 500</item>
</string-array>
In java :
String[] data=getResources().getStringArray(R.array.large_string_data);
//use it with id numbers
String question_two=data[1];
2. text file
Pros: Great if you want your strings in just 1 language and it will not be translated in other languages.
Cons: If not handle properly ,can lead to IOException and file handling exception + every time you open your app you have to open streams to read that file
3. Database(SQL)
Pros: Best for storing large strings data and you can create different tables for different languages and store your string there , Its light, fast and easy to access .Less error prone than text files (Recommended)
Upvotes: 1
Reputation: 965
For saving 500 to 5000 string you could use Json file to save data. And its very easy to use. The following link will help you Android Java; How can I parse a local JSON file from assets folder into a ListView
Upvotes: 3