请问字符串硬编码影响性能? [英] Does hard coding of string affect performance?

查看:927
本文介绍了请问字符串硬编码影响性能?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

每当我做任何应用程序,我总是很难code中的字符串,而不是从字符串资源从XML引用它。应用程序工作正常,但给我的警告使用 @string 资源

Whenever I make any app I always hardcode the string instead of referencing it from string resource from XML. App works fine but gives me warning to use @string resource

例如按钮:

<Button
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="click here" />

我的问题是,它是否会影响我的应用程序的性能,如果我这样做,或者(@string 资源<$ C C $>)仅仅是用于国际化。

My question is whether it will affect my application performance if I do so or it(@string resource) is just used for internationalization.

推荐答案

这是一个Android皮棉警告,以帮助您定位。

This is an Android lint warning to help you with localization.

从技术上讲,硬编码字符串,将让你的应用程序执行好一点,因为它不会有来查找字符串对应的研究 INT每次从。然而,这种性能上的​​差异将是微不足道的,并且没有人将能够注意到它。

Technically, hard coding strings would make your app perform a little better, as it won't have to look up the string from the corresponding R int each time. However, this performance difference will be negligible, and no human will be able to notice it.

不过,你应该的总是的保持你的字符串资源的价值的文件夹,因为它使本地化很容易的。

However, you should always keep your String resources in the values folder as it makes localization very easy.

这篇关于请问字符串硬编码影响性能?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆