class Application

官方描述:Base class for those who need to maintain global application state. You can provide your own implementation by specifying its name in your AndroidManifest.xml's <application> tag, which will cause that class to be instantiated for you when the process for your application/package is created.

为应用程序提供全局变量的基础类,你可以自己实现application通过在AndroidManifest.xml的<application>标签指定它的名字,此举会导致在应用程序的进程被建立时此类被实例化。

There is normally no need to subclass Application. In most situation, static singletons can provide the same functionality in a more modular way. If your singleton needs a global context (for example to register broadcast receivers), the function to retrieve it can be given a Context which internally uses Context.getApplicationContext() when first constructing the singleton.

实现Application的子类不是必须的。在大多数情况下,静态单例模式可以以一个模块化的方式实现相同功能。如果你的单例模式需要一个全局context,恢复使用Application可以在你第一次创建单例时通过使用Context.getApplicationContext()获取一个Context。

一个Application是一个进程,Application为整个程序提供Context。

Application类继承

  1. java.lang.Object:根类
  2. android.content:包含类用来在设备上获取和发布数据。android.content.ContextWrapper:Context的代理,简单的代表它的所有需求到另一个Context.Wrapper:包装.
    •      Content sharing:用于在不同应用组件间分享内容。
    • Package management:获取安卓包的信息,包括activities, permissions, services, signatures, and providers
    • Resource management:检索与应用相关的资源ID,例如strings, drawables, media, and device configuration details。

    • Context:获取应用程序环境的全局信息,由系统提供实现的抽象类,它允许获取应用具体的资源,并可实现应用程序级别的操作,例如启动活动,广播和接受intents
  3. android.content.ContextWrapper:Context的代理。
  4. android.app.Application

由Application类继承可以看到,Application类继承自ContextWrapper类,而ContextWapper类继承自Context类;
Context类主要用于描述应用程序环境和获取应用程序资源和类,以及应用程序级别的操作。
四大组件活动,广播,服务,内容提供器;这些组件建立后,应用程序才会建立,应用程序只是一个概念,用于包含组件。

android.content.Context
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值