Why it is impossible to access resources in a static way?

后端 未结 1 1362
执念已碎
执念已碎 2021-01-18 05:08

I know now, that if I need to get a recource in some static function, I have to pass context or recources of the context there somehow - by parameter or through a static var

相关标签:
1条回答
  • 2021-01-18 05:47

    The resource IDs are unique per application, they are not unique over all application (including the Android system). E.g. there may be two different string in different applications which have the same ID, say 42. Therefore yon may access only one application statically (every programmer must agree which one that is, its the Android system (there no choice, its the only one always installed)). For all the other application you must be able to tell the system which application's resources you want to access. You do this using the context.

    0 讨论(0)
提交回复
热议问题