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

android 比较符合android构架,优雅的定义全局变量

2010-08-24 18:28 441 查看
android.app.Application

 

api 是这样描述的。

 

Base class for those who need to maintain global application state. You can
provide your own implementation by specifying its name in your
AndroidManifest.xml's <application> tag, which will cause that class
to be instantiated for you when the process for your application/package is
created.

 

 

所以可以定义一个application,并在AndroidManifest.xml声明,

 

便可以在其他 activity 中通过 (application)getApplicationContext()获取该实例来操作变量。

 

 

当然java通用做法设置静态变量也是可行的!

 
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息