首页 > 移动平台 > 详细

Android全局变量使用

时间:2014-05-09 20:50:11      阅读:423      评论:0      收藏:0      [点我收藏+]

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





Android全局变量使用,布布扣,bubuko.com

Android全局变量使用

原文:http://blog.csdn.net/honjane/article/details/25418045

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!