-1

How can you access variables content in

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

}

from a Public class like this one?

Public Class MyApp {

}

I tried with

Global Username = (Global) getApplicationContext();

but I found out getApplicationContext(); is used for Activities only.

How should I do it then?

Thanks for your help!

1 Answers1

0

Make the variables in the Global class static.

static String variable;

then you can access them by doing String stuff = Global.variable;

CoderOfHonor
  • 741
  • 7
  • 17
  • Don't make a new Instance of the `Application` object, Applications, Activities, Services are not meant to be directly instantiated. – A--C Jan 30 '13 at 22:16
  • @A--C Oh yeah, didn't think about what he was extending. I'll fix it. – CoderOfHonor Jan 30 '13 at 22:17
  • Amazingggg! Thanks! I've been looking for a solution the whole day! I understand that it might not be the proper way to do it, but my time is counted and I'm learning this step by step. Thanks again!! – user2023276 Jan 30 '13 at 22:30