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的继承关系后,我们接下来分析应用程序在什么情况需要创建Context对象的?应用程序创建Context实例的

 情况有如下几种情况:

      1、创建Application 对象时, 而且整个App共一个Application对象

      2、创建Service对象时

      3、创建Activity对象时

 

    因此应用程序App共有的Context数目公式为:

 

                     总Context实例个数 = Service个数 + Activity个数 + 1(Application对应的Context实例)

posted @ 2015-10-28 09:26  无天666  阅读(305)  评论(0编辑  收藏  举报