美文网首页
android Resource

android Resource

作者: 一个简单搬运工 | 来源:发表于2018-07-16 16:42 被阅读14次
getResources()用在有context的地方,没有context的地方和静态类中是不能用的(也有开发者通过一些方式对context进行封装用在静态类中),而且getResources()只能用于获取应用本身的资源
Resources.getSystem() 可以在任何地方进行使用,但是有一个局限,只能获取系统本身的资源

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

相关文章

网友评论

      本文标题:android Resource

      本文链接:https://www.haomeiwen.com/subject/bumbpftx.html