6

I saw this post that says when strings.xml gets too big the app may crash. My strings.xml file is 800 plus lines right now and it will be a lot bigger in a while.

The answers in the post say that using a SQLite database can prevent the crash.

But in my case I have a SQLite database that takes the data for the entries from strings.xml because my app uses locales for different languages.

My question is, how big can strings.xml be? And if I hit the line limit what can I do to prevent the crash?

Bokis
  • 3
  • 3
Thelouras
  • 812
  • 1
  • 12
  • 23
  • What did your logcat says – Killer Dec 23 '18 at 10:32
  • as i said there is no a crash right now, but the post that i linked says if the strings.xml is to big the app will be crash. My strings.xml will be to big in a while, my question is how big can strings.xml can be ? – Thelouras Dec 23 '18 at 10:35
  • 1
    Why can't you use SQLite *directly*? Meaning one table for each language? Just choose the language table you need and use the strings stored inside that one. – Phantômaxx Dec 23 '18 at 14:29
  • @Fantômas because the app was designed from the beginning like this and we are using locale with strings resources. And it wants a lot of work to transfer all the data from strings.xml in new tables. Maybe it will be done in a future refactoring! – Thelouras Dec 23 '18 at 15:19

2 Answers2

2

The Resources.get*** methods doesn't have any explicit limitation, so it depends on your device's memory size. And as I know the old version of Android has per process memory limitation.

shingo
  • 6,928
  • 4
  • 13
  • 29
  • So that is not about how big strings.xml is ? but about the Resources.get*** method ? – Thelouras Dec 23 '18 at 11:13
  • Beacause my strings.xml file will be 1000+ lines. It is not a problem ? – Thelouras Dec 23 '18 at 11:14
  • 1
    Because you read strings.xml with Resources' methods. 1000+ lines in an xml file is not extravagant. You just need to take care of the memory usage. – shingo Dec 23 '18 at 13:00
1

There is no limitation of the strings.xml. Its more a problem of loading a string array. The getResources().getStringArray function is not meant to load arrays with more elements than 512 (more about this here Should I be using something other than getResource().getStringArray() to populate a large array?) But as long as you are not using big arrays you should be fine.

Hansfritzi
  • 82
  • 6