Android 公共类和全局变量

Android 公共类和全局变量,android,class,global,Android,Class,Global,如何访问内容中的变量 public class Global extends Application { String gotUsername; String gotPassword; String gotIPAddress; void onStartCommand(Intent intent){ Bundle gotAuthen = intent.getExtras(); gotUsername = gotAuthen.

如何访问内容中的变量

    public class Global extends Application {
    String gotUsername;
    String gotPassword;
    String gotIPAddress;

    void onStartCommand(Intent intent){
        Bundle gotAuthen = intent.getExtras();
        gotUsername = gotAuthen.getString("key1");
        gotPassword = gotAuthen.getString("key2");
        gotIPAddress = gotAuthen.getString("key3"); 
    }

    protected void onCreate(Bundle savedInstanceState) {
        // TODO Auto-generated method stub
        super.onCreate();
    }

}
从像这样的公共课上

Public Class MyApp {

}
我试过了

Global Username = (Global) getApplicationContext();
但是我发现
getApplicationContext()仅用于活动

那我该怎么做呢


谢谢你的帮助

使
全局
类中的变量保持静态

static String variable;

然后您可以通过执行
String stuff=Global.variable

不要创建
应用程序的新实例
对象、应用程序、活动和服务都不是直接实例化的。@a--C哦,是的,没有考虑他在扩展什么。我会修好的,太棒了!谢谢我一整天都在寻找解决办法!我知道这可能不是正确的方法,但我的时间是有限的,我正在一步一步地学习。再次感谢!!