Implementation of getResources() Android

家住魔仙堡 提交于 2019-12-01 09:39:19

Your activity extends class android.app.Activity which in turn extends class android.content.Context (three levels up the class hierarchy). Class Context declares the abstract method getResources() which means that your activity subclass inherits that method and you can call it from within your onCreate() method (for example).

The method getResources() is declared as abstract in class Context but one of the intermediate classes in the class hierarchy (android.view.ContextThemeWrapper) provides an implementation for the method.

Also that means that creating the Resources object is not your responsibility; it is done by the framework instead.

getResources is actually a method you can access from your Context. So you can really think of this as:

context.getResources()

Your Activity class is your context in this case, which is why you can just call it with the syntax:

getResources()

http://developer.android.com/reference/android/content/Context.html#getResources%28%29

From those docs:

Interface to global information about an application environment. This is an abstract class whose implementation is provided by the Android system. It allows access to application-specific resources and classes, as well as up-calls for application-level operations such as launching activities, broadcasting and receiving intents, etc.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!