Android: How to declare global variables?
Posted
by
niko
on Stack Overflow
See other posts from Stack Overflow
or by niko
Published on 2009-04-02T01:54:30Z
Indexed on
2011/01/09
21:53 UTC
Read the original article
Hit count: 182
android
|global-variables
Hi,
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 condition:
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
...
loadSettings();
if(strSessionString == null)
{
login();
}
...
}
The onActivityResult method which is executed when the login form terminates looks like this:
@Override
public void onActivityResult(int requestCode,
int resultCode,
Intent data)
{
super.onActivityResult(requestCode, resultCode, data);
switch(requestCode)
{
case(SHOW_SUBACTICITY_LOGIN):
{
if(resultCode == Activity.RESULT_OK)
{
strSessionString = data.getStringExtra(Login.SESSIONSTRING);
connectionAvailable = true;
strUsername = data.getStringExtra(Login.USERNAME);
}
}
}
The problem is the login form sometimes appears twice (the login() method is called twice) and also when the phone keyboard slides the login form appears again and I guess the problem is the variable strSessionString.
Does anyone know how to set the variable global in order to avoid login form appearing after the user already successfully authenticates?
Thanks!
© Stack Overflow or respective owner