Context字面意思上下文,位于framework package的android.content.Context中,其实该类为LONG型,类似Win32中的Handle句柄,很多方法需要通过Context才能识别调用者的实例。

比如说Toast的第一个参数就是Context。一般在Activity中我们直接用this代替,代表调用者的实例为Activity,而到了一个button的onClick(View view)等方法时,我们用this时就会报错,所以我们可能使用ActivityName.this来解决,主要原因是因为实现Context的类主要有Android特有的几个模型,Activity、Service以及BroadcastReceiver。

常规需要Context实例的方法主要有各种Service实现的类,比如说SensorManager在实例化时需要

getSystemService(String)方法就必须由Context的实例执行,还有一些私有的文件系统I/O比如说

openFileInput以及常用的Toast的makeText方法。

android.content.Context 含义及使用的更多相关文章

  1. java.lang.NoSuchMethodError:android.content.Context.getDrawable

    今天在开发的时候,这个代码在源码中是可以看到的,但是在android 4.3手机上面会报错,具体错误信息和代码如下: setBackgroundDrawable(context.getDrawable ...

  2. Caused by: java.lang.NoSuchMethodException: <init> [class android.content.Context, interface android.util.AttributeSet] 异常

    1. 异常描述 FATAL EXCEPTION: main Process: com.whereru.greengrass.goforit, PID: 13847 java.lang.RuntimeE ...

  3. Caused by: java.lang.NoSuchMethodException: &lt;init&gt; [class android.content.Context, interface android

     在写自己定义的view时,有时会报下面错误: Caused by: java.lang.NoSuchMethodException: <init> [class android.co ...

  4. No implementation found for void `org.webrtc.PeerConnectionFactory.initializeAndroidGlobals(android.content.Context, boolean)

    背景介绍 最近在使用 AndroidRTC 利用WebRtc屏幕共享时使用PeerConnectionFactory.initializeAndroidGlobals(context, true, t ...

  5. java.lang.NoSuchMethodException: &lt;init&gt; [class android.content.Context, interface androidutil.Attri

    <pre name="code" class="java"><span style="font-size:24px;"&g ...

  6. Android中Context详解

    大家好,  今天给大家介绍下我们在应用开发中最熟悉而陌生的朋友-----Context类 ,说它熟悉,是应为我们在开发中时刻的在与它打交道,例如:Service.BroadcastReceiver.A ...

  7. Android中Context详解 ---- 你所不知道的Context

    转自:http://blog.csdn.net/qinjuning/article/details/7310620Android中Context详解 ---- 你所不知道的Context 大家好,  ...

  8. 转:Android中Context详解 ---- 你所不知道的Context

    转:http://blog.csdn.net/qinjuning/article/details/7310620 转:http://blog.csdn.net/lmj623565791/article ...

  9. Android中Context具体解释 ---- 你所不知道的Context

                                                                                                         ...

随机推荐

  1. VirtualBox内Linux系统与Windows共享文件夹

    在日常工作或学习中我们经常需要在一台电脑上同时使用Windows和Linux(这里以Ubuntu为例)两个系统,我们通常的做法有两种: 一种安装双系统(双系统的安装方法经验里已经有很多,大家可以去参照 ...

  2. OC面向对象多态笔记

    面向对象的多态是建立在继承上,可以说没有继承就没有多态: 多态:父类指针指向了子类的对象: int main() { //假设已定义了Animal类和它的子类Dog,那么多态的代码体现就是 Anima ...

  3. android 开发 实现自动安装

    场景:实现自动安装apk程序 注意:不能使用 intent.setDataAndType(Uri.parse(apkPath),  "application/vnd.android.pack ...

  4. Text selection in div(contenteditable) when double click

    背景: 在最近项目中,碰到一个问题:有一个可编辑的div需要双击时可编辑,blur或者回车时将编辑结果保存.你可能注意到双击时,文字会被选中,可编辑区域不会focus到光标位置.考虑到兼容性问题,写了 ...

  5. How to avoid C# console applications from closing automatically.

    One way is to interop it with msvcrt.dll You can pinvoke this C function into your C# application. T ...

  6. php发送get、post请求的几种方法

    方法1: 用file_get_contents 以get方式获取内容 <?php $url='http://www.domain.com/'; $html = file_get_contents ...

  7. FTP操作类(支持异步)

    public delegate void DownloadProgressChangedEventHandle(string information, long currentprogress, lo ...

  8. 1304: [CQOI2009]叶子的染色 - BZOJ

    Description给一棵m个结点的无根树,你可以选择一个度数大于1的结点作为根,然后给一些结点(根.内部结点和叶子均可)着以黑色或白色.你的着色方案应该保证根结点到每个叶子的简单路径上都至少包含一 ...

  9. BZOJ 4031: [HEOI2015]小Z的房间 Matrix-Tree定理

    题目链接: http://www.lydsy.com/JudgeOnline/problem.php?id=4031 题解: Matrix-tree定理解决生成树计数问题,其中用到高斯消元法求上三角矩 ...

  10. oracle 用户 多个表空间

    首先,授权给指定用户. 一个用户的默认表空间只能有一个,但是你可以试下用下面的语句为其授权在别的表空间中创建对像: alter user  username quota 0||unlimited on ...