android 获取全局上下文
来源:互联网 发布:unity3d 液体流动 编辑:程序博客网 时间:2024/05/21 22:43
有时我们在除activity外的代码里,我们也需要一个上下文,虽然我们也可以通过传值的形式把上下文传过来,但是这样做会是你的代码的参数增多, 而且每遇到这样的情况你都的传一个上下文,这样就很麻烦,所以我们就会用到所谓的全局的上下文: getApplicationContext(); 如何得到呢? 在我们的工程里创建一个我们自己的application,BaseApplication继承application
public class BaseAppliction extends Application { private Context context; @Override public void onCreate() { super.onCreate(); context = getApplicationContext(); } public Context getContext(){ return context; }}
使用时:
BaseAppliction app = (BaseAppliction)getApplication(); Context context = app.getContext();
这样就完全不用再考虑去别的地方传一个上下文了
1 0
- android 获取全局上下文
- Android全局获取Context上下文实例
- 获取全局的上下文
- Android获取Context(任意位置任意地方,全局上下文)
- 安卓-获取全局上下文
- Android获取上下文Context
- Android关于context上下文定义全局的
- android 获取全局context
- Android全局获取Context
- android 获取全局context
- Android全局获取Context
- Android---全局获取Context
- android获取全局context
- 关于JSP中获取全局上下文不能识别的问题
- Android JNI获取上下文Context
- Android 如何全局获取Context
- Android 如何全局获取Context
- Android 如何全局获取Context
- python基本图像操作
- grep 命令系列:如何在 Linux/UNIX 中使用 grep 命令
- youku的js脚本的工具函数和初始化方法
- java解决对US7ASCII编码的ORACLE数据库数据解码
- add "shadow+border+corner" specially for UIView
- android 获取全局上下文
- Java关键字transient
- 在ASP.NET MVC中,App_Start/BundleConfig.cs来打包压缩js和css
- srxboys自述
- ubuntu No protocol specified
- Android方法数
- 解决iOS UITextField输入的内容在代理方面里面不能全部获取到
- javascript 抽奖程序
- 有1个月没有写博客了,因为……