`
yanfaguanli
  • 浏览: 662934 次
文章分类
社区版块
存档分类
最新评论

Android全局变量使用

 
阅读更多

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();





分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics