Android全局变量使用
2014-06-25 09:41
417 查看
1、通过一个Data.java实例类,能够实现全局数据保存,这里就不多说了,学Java的都知道。
2、Android特有的Application,是应用的入口,执行贯穿整个app执行过程,能够在这个类中定义全局变量
使用时候直接调用:
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 使用全局变量
- Android 使用全局变量 (转)
- Android中用Application类实现全局数据变量的使用
- Android入门篇四:使用全局变量在Activity之间传递数据
- android 使用Intent传递数据之全局变量传递
- Android中application 全局变量 && 使用TAB页不能退出的问题
- Android用Application设置全局变量以及使用
- Android学习札记49:在Android中使用Application保存全局变量
- android 使用Application保存全局变量
- Android入门篇五:使用全局变量在Activity之间传递数据
- Android 使用全局变量
- Android application对象的使用 全局变量
- android中使用全局变量
- android中使用全局变量
- Android 使用全局变量
- Android application对象的使用 全局变量
- android使用全局变量
- Android使用Application代替全局变量
- Android 使用全局变量
- Android用Application设置全局变量以及使用