extend the base android.app.Application class and add member variables like so:

public class MyApplication extends Application {

private String someVariable;

public String getSomeVariable() {
return someVariable;
}

public void setSomeVariable(String someVariable) {
this.someVariable = someVariable;
}
}

In your android manifest you must declare the class implementing android.app.Application:

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

Then in your activities you can get and set the variable like so:

// set
((MyApplication) this.getApplication()).setSomeVariable("foo");

// get
String s = ((MyApplication) this.getApplication()).getSomeVariable();

更多相关文章

  1. 代码中设置drawableleft
  2. android 3.0 隐藏 系统标题栏
  3. Android开发中activity切换动画的实现
  4. Android(安卓)学习 笔记_05. 文件下载
  5. Android中直播视频技术探究之—摄像头Camera视频源数据采集解析
  6. 技术博客汇总
  7. android 2.3 wifi (一)
  8. AndRoid Notification的清空和修改
  9. Android中的Chronometer

随机推荐

  1. Android(安卓)Studio更改SDK或者JDK路径
  2. How to set Android(安卓)camera orienta
  3. Android(安卓)图片缩放,手势,事件
  4. Android中xml生成
  5. Android:Google Play services and OAuth
  6. android samsung note3  device not fou
  7. Android评论留言页面
  8. Android中下拉列表框操作
  9. android 脸部抠图
  10. Android(安卓)项目混编flutter报错