Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Best practice for saving long text in Android

I would like to know if it always best practice to store String values in the strings.xml file, even when the String(s) are really large. To be more specific, I have a game, where I display the rules of the game. The sum of all characters is bigger then 700 characters. Currently I break those long Strings into smaller Strings (into paragraphs). So I was wondering, would it be considered as good practice to have those long Strings, containing more then 700 characters? I know the HEAP size has to be considered how much characters can be addressed, but I doubt you can easily hit the limit. From what I was reading Java has the limit set to (2^31 - 1) characters and in Android to somewhere 4-64 million characters.

like image 954
Jernej K Avatar asked Oct 19 '22 11:10

Jernej K


1 Answers

I don't think there is an upper limit to storing strings in xml, so it would be most convenient to store the strings there.

If really want to go for different mechanism, you can either go for database, or file. But, reading from database and file would take time as compared to reading from the xml file, and it would require more code to achieve the same thing.

Edit :

I just noticed that the string you are referring to are the rules of the game. So I'd strongly recommend to go with strings.xml because android uses that XML to enable translating your app into different languages

From the official guidelines on localization:

Move all strings into strings.xml. As you build your apps, remember not to hard code any string. Instead declare all of your strings as resources in a default strings.xml file which makes it easy to update and localize. Strings in strings.xml file can be extracted, translated and integrated back into your app (with appropriate qualifiers) without any changes to compiled code.

like image 115
Yash Avatar answered Oct 21 '22 06:10

Yash