Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
708 views
in Technique[技术] by (71.8m points)

what's wrong with hardcoded string in android xml file?

I love to put simple text directly on the xml file without declaring a string first. It is easier, more simple and less messy. However, it always has a warning badge whenever I do so.

What if I have a dozens of hardcoded string in my xml file without concerning the warning? Will I get into a trouble?

thanks in advance.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

When you use hard coded strings in both you java code and xml file your application directly writes these strings on RAM. But when you declare them as string resources it will not be written on RAM when application launches but they are written on RAM when application needs to use them. You can declare one billion strings in resources and you can still have a light weight RAM friendly Android application.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...