Resources.getSystem() vs getResources()

后端 未结 3 2074
死守一世寂寞
死守一世寂寞 2021-02-07 07:10

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:

Type 1:

3条回答
  •  遇见更好的自我
    2021-02-07 07:26

    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

提交回复
热议问题