Application Context
一个android应用中一般包含以下组件(component):activities, services, content providers, and broadcast receivers.这些组件都在同一个application context中。
Application Context 引用应用的环境和应用中的组件运行的进程(process)。它允许应用在不同的构建块之间共享数据和资源。
Application context refers to the application environment and the process within which all its components are running. It allows applications to share the data and resources
between various building blocks.
application context在应用程序的第一个组件(不论是activity还是services...)启动的时候被创建。
An application context gets created whenever the first component of this application is started up, regardless of whether that component is an activity, service, or something
else.
Application context的生命周期:它不依赖于activity的生命周期,它和应用共存。
Application context lives as long as your application is alive. As such, it is independent of the activities life cycle.
你可以通过 Context.getApplicationContext()or Activity.getApplication()来获取一个应用上下文的引用。
Activity和Service是Context的子类,它们集成了Context的所有方法。
You can easily obtain a reference to the context by calling Context.getApplicationContext()or Activity.getApplication(). Keep in mind
that activities and services are already subclasses of context, and as such they inherit all its methods
原书:《Oreilly.Learning.Android.Mar.2011》
阅读(1276) | 评论(0) | 转发(0) |