title: How to declare global variables in Android?
body: <p>I am creating an application which requires login. I created the main and the login activity.</p>
  
  <p>In the main activity <code>onCreate</code> method I added the following condition:</p>
  
  <pre><code>public void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      setContentView(R.layout.main);
  
      ...
  
      loadSettings();
      if(strSessionString == null)
      {
          login();
      }
      ...
  }
  </code></pre>
  
  <p>The <code>onActivityResult</code> method which is executed when the login form terminates looks like this:</p>
  
  <pre><code>@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);
              }
          }
      }
  </code></pre>
  
  <p>The problem is the login form sometimes appears twice (the <code>login()</code> method is called twice) and also when the phone keyboard slides the login form appears again and I guess the problem is the variable <code>strSessionString</code>.</p>
  
  <p>Does anyone know how to set the variable global in order to avoid login form appearing after the user already successfully authenticates?</p>