0

I have a list of strings (messages and urls) which I want to place in a common file. Would it be more efficient to place them in a container class or as an xml resource?

If I want to use the strings in my xml layouts, I guess I have to put my string in an xml resource?

Edit: I know the advantages of both approaches, all I want to know is which is faster.

Arnab Chakraborty
  • 7,442
  • 9
  • 46
  • 69

1 Answers1

1

XML resources are actually compiled to binary form when you create your APK, so they are pretty fast. If you use resources, you can define different string for different languages (locales), versions or screen sizes, and the platform takes care of using the right one automatically. There is no reason to use a container class, use XML resources.

Nikolay Elenkov
  • 52,576
  • 10
  • 84
  • 84
  • I know that they are pretty fast. I am just asking which is faster xml resource or container classes? – Arnab Chakraborty Aug 11 '11 at 05:48
  • I don't know. Benchmark it, if you really need numbers. Another thing to note is that there are some resources limitations on older platforms: no more than 512 elements (IIRC) in an resource string array, etc. That's one case where you may need to use a container class. – Nikolay Elenkov Aug 11 '11 at 06:46
  • Measure the time it takes to load resources, compare with the time it takes to load class fields. – Nikolay Elenkov Aug 11 '11 at 06:51