I am creating an application which requires login. I created the main and the login activity.
In the main activity onCreate
method I added the following
You could create a class that extends Application
class and then declare your variable as a field of that class and providing getter method for it.
public class MyApplication extends Application {
private String str = "My String";
synchronized public String getMyString {
return str;
}
}
And then to access that variable in your Activity, use this:
MyApplication application = (MyApplication) getApplication();
String myVar = application.getMyString();