Why is using string literals in Android discouraged? What other/better alternatives are available?

女生的网名这么多〃 提交于 2019-12-24 14:46:58

问题


I know that using string literals in Android is discouraged but I do not know why. I also would like to know what possible ways can get round this problem.


回答1:


It's not necessarily a problem, just a warning. Android encourages the use of the strings resource file where possible but you certainly can hard-code strings and have it work correctly.

See this question/answers: what's wrong with hardcoded string in android xml file?




回答2:


This isn't an Android-specific issue. It is a "best practice" for programming in general. It is always a good idea to put strings and other "localizable" data into separate files (properties files, resources, etc.). This makes localization into other languages much easier.



来源:https://stackoverflow.com/questions/29501520/why-is-using-string-literals-in-android-discouraged-what-other-better-alternati

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!