Android中,Context,什么是Context

如题所述

  Context,中文直译为“上下文”,SDK中对其说明如下:

         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

 

    ä»Žä¸Šå¯çŸ¥ä¸€ä¸‹ä¸‰ç‚¹,即:

        1、它描述的是一个应用程序环境的信息,即上下文。

        2、该类是一个抽象(abstract class)类,Android提供了该抽象类的具体实现类(后面我们会讲到是ContextImlç±»)。

        3、通过它我们可以获取应用程序的资源和类,也包括一些应用级别操作,例如:启动一个Activity,发送广播,接受Intent

      ä¿¡æ¯ ç­‰ã€‚。

 

 

   于是,我们可以利用该Context对象去构建应用级别操作(application-level operations) 。

 

 ä¸€ã€Context相关类的继承关系





其实呢,在activity中,context就是当前这个activity对象

在Service中,context就是当前这个Service对象

整个应用程序它也是一个Context,但是通过 getApplicationContext 来获取的

这个context是你在AndroidManifest.xml   application 节点中定义的类


 

                         

温馨提示:答案为网友推荐,仅供参考
相似回答