Android Context概要
来源:互联网 发布:java里变量定义 编辑:程序博客网 时间:2024/06/14 15:06
一、Context概述
Context中文直译是上下文,我想和我一样汉语一般的人来说,这个译法提供不了什么有用的信息。就其作用而言,Context类似于我们在Win32编程时的句柄,通过这个句柄,我们可以访问到其他一些资源或者和某些对象关联起来。
二、Context对象的分类
1、应用程序的Context,每一个应用程序都有唯一的一个。
2、Activity和Service的Context,每个Activity和Service都有不同的Context。
这两种Context最重要的区别就是生命周期的不同,Application的Context的生命周期和整个程序的周期相同,而Activity和Service的Context的生命周期和Activity/Service的生命周期相同。
三、Context对象的获取
获取Context的方法主要有:getApplicationContext()、getContext()、getBaseContext()。另外:
因为Activity和Service是Context的子类,所以在Activity/Service或其子类中可以通过 this来获取其Context对象。
四、Context对象的作用
1、创建新的对象:如创建View、Adapter对象都需要Context对象,该Context对象一般是Activity/Service的Context,由这个Context确定View和Adapter的所属。
2、访问系统的资源:如调用Context的getSystemService(XXX)来获取系统服务。
3、访问其他的组件:如获得应用程序的的ContentResolver, getContentResolver()。
- Android Context概要
- Android - Context, What Context?
- Android Context, What Context?
- android context
- android context
- android context
- Android Context
- Android-Context
- Android Context
- android context
- Android Context
- Android Context
- android Context
- Android Context
- android context
- android context
- android context
- Android Context
- 我;恩里克;水电费;刘东说了;的;浪费时间
- const char*, char const* and char *const
- java将html导出成word(利用的poi包导出)
- 创建高安全性PHP网站的几个实用要点
- Java的高级特性反射
- Android Context概要
- SQL语句中的锁定语句
- python语法中字符串(string)的print和format
- 背包九讲
- MFC Static上显示JPG图像,如何使图像大小自适应Static边框
- 百度还是总喜欢把你我这样的草根站长玩弄在手掌之间
- MyEclipse10 开发 Android 环境配置
- Unity3D环境下的GLSL shaders写法 — 纯色参数
- 编写webservice服务端和客户端实例(2)