Resources.getSystem()与getResources() [英] Resources.getSystem() vs getResources()

查看:93
本文介绍了Resources.getSystem()与getResources()的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是Android的新手,我正在从网上获得的资源中自己学习SDK.

I am new to Android and I am learning the SDK myself from resource available over the net.

我现在遇到了一个情况.我正在尝试以下代码:

I came across a situation now. I am trying the below code:

类型1: getResources().getString(android.R.string.cancel);

类型2: Resources.getSystem().getString(android.R.string.cancel);

类型3: getString(android.R.string.cancel);

以上所有方法均返回相同的值.那么这些方法是什么,它们的用例是什么.什么时候使用哪种方法有哪些好的做法.请帮帮我.

All of the above methods return the same value. So what are these methods, what are their use cases. What are the good practices on when to use which method. Please help me out.

推荐答案

不同之处不仅在于所获得的,还在于您可以在何处使用它们.

The difference is not only in what you get, but in WHERE can you use them.

第一个和第三个使用上下文".看不见的因此,在很多情况下(在静态成员中或活动成员之外),您不能直接使用它们,除非您将上下文或资源作为静态变量或参数传递到您的作用域中.但是第二个

The first and the third ones are using "context." invisibly. So, very often (in static members or out of activity members) you can't use them directly, unless you pass context or resource as a static variable or as a parameter into your scope. But the second one

Resources.getSystem().getString(android.R.string.cancel)

即使在静态常量声明中,您也可以在应用程序中的任何地方绝对使用它!但是仅用于系统资源

You can use ABSOLUTELY EVERYWHERE in your application, even in static constants declaration! But for system resources only

这篇关于Resources.getSystem()与getResources()的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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