在Intent中来回的传一些所谓的全局变量实在苦手,上网搜了搜,果然有省事的方案(http://stackoverflow.com/questions/708012/android-how-to-declare-global-variables)可以用继承Application来享元~~直接贴代码~

public class ShareContext extends Application {private PHPRPC_Client client;public PHPRPC_Client getClient() {return client;}public void setClient(PHPRPC_Client client) {this.client = client;}}

然后在AndroidManifest.xml中设置name属性

<application android:name=".ShareContext" android:icon="@drawable/icon" android:label="@string/app_name">

设置享元:

ShareContext shareContext = ((ShareContext)getApplicationContext());shareContext.setClient(client);

读取享元:

ShareContext shareContext = ((ShareContext)getApplicationContext());PHPRPC_Client client = shareContext.getClient();

好东西~~直接省了很多事!!

更多相关文章

  1. android webview设置缩放按钮时候无法显示问题
  2. Android(安卓)开发所有权限解析
  3. Android去掉标题栏及崩溃问题
  4. Android的Dialog开发和运用
  5. android―label窗口――基础编
  6. Android(安卓)启动分析-init进程&init.rc[转]
  7. Android仿易信界面SlidingMenu左右滑动
  8. android 设置默认语言 多语言切换
  9. ActionBar(2) 标题和渐变背景设置

随机推荐

  1. android: layout_gravity VS android: gr
  2. Android(安卓)Intents
  3. android 程序 发布加密
  4. Android Studio设置HTTP代理
  5. Android中的单元测试
  6. Android平板大屏幕的设置
  7. Android(安卓)资源文件中@、@android:typ
  8. Failed to get the adb version: Cannot
  9. Android(安卓)初级(待续)
  10. Android(安卓)Theme的设置