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

Android全局变量使用

2014-06-25 09:41 417 查看
1、通过一个Data.java实例类,能够实现全局数据保存,这里就不多说了,学Java的都知道。

2、Android特有的Application,是应用的入口,执行贯穿整个app执行过程,能够在这个类中定义全局变量

public class baseApplication extends Application {

private float screenWidth;
private float screenHeight;

public float getScreenWidth() {
return screenWidth;
}
public void setScreenWidth(float screenWidth) {
this.screenWidth = screenWidth;
}
public float getScreenHeight() {
return screenHeight;
}
public void setScreenHeight(float screenHeight) {
this.screenHeight = screenHeight;
}

}


使用时候直接调用:

baseApplication b=(baseApplication) getApplicationContext();
float width=b.getScreenWidth();
float height=b.getScreenHeight();
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: