您的位置:首页 > 移动开发 > Android开发

解开迷惑——Android Context究竟是什么

2014-11-05 10:39 543 查看
Android应用开发常会用到context,但是对于初学者来说,context的概念很抽象。那么Context究竟有什么用以及怎么用呢?

首先看SDK对Context下的定义:

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.

从这段话可以看出,Context是一个抽象类,通过它我们可以获取应用程序的资源和类,也可以做应用级的操作,如:启动activity,发送广播,接收intent信息等。

那么Context怎么用呢?

1.何时创建

1⃣️创建Application对象时,而且整个App共用一个Application对象。

2⃣️创建Activity对象时。

3⃣️创建Service对象时。

……待续

ref:http://www.xcoder.cn/html/mobile/android/2013/0316/2436.html
http://www.2cto.com/kf/201109/103998.html
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: