Android ::: How to set variable global / to avoid login form appearing after successful authentication


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?

Popular Posts