What is 'Context' on Android?

前端 未结 30 2922
南旧
南旧 2020-11-21 04:46

In Android programming, what exactly is a Context class and what is it used for?

I read about it on the developer site, but I am unable to understand it

30条回答
  •  后悔当初
    2020-11-21 05:18

    Instances of the the class android.content.Context provide the connection to the Android system which executes the application. For example, you can check the size of the current device display via the Context.

    It also gives access to the resources of the project. It is the interface to global information about the application environment.

    The Context class also provides access to Android services, e.g., the alarm manager to trigger time based events.

    Activities and services extend the Context class. Therefore they can be directly used to access the Context.

提交回复
热议问题