Chinaunix首页 | 论坛 | 博客
  • 博客访问: 2537464
  • 博文数量: 245
  • 博客积分: 4125
  • 博客等级: 上校
  • 技术积分: 3113
  • 用 户 组: 普通用户
  • 注册时间: 2009-03-25 23:56
文章分类

全部博文(245)

文章存档

2015年(2)

2014年(26)

2013年(41)

2012年(40)

2011年(134)

2010年(2)

分类: Android平台

2013-04-27 13:27:46

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》
阅读(1239) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~