title: Create Session with Android Java Firebase
body: <p>I am using email and password. I have create user and authenticate user but I don't know how to add a session for this user.</p>
  
  <p>For example, if the user logs into his/her account. He/she is able to delete the application's process on their phone when they do not want to use the app, then  get rid of the app's process and the session is should still be ongoing, therefore when they go back to their application they should still be logged in until he/she logs out (unauth).</p>
  
  <p>I am having trouble making a session for a logged in user. I believe a token must be used but I have no idea how I should use it.</p>
  
  <p>Login Activity:</p>
  
  <pre><code>Firebase user_data = new Firebase("https://myapp.firebaseio.com"); 
  user_data.authWithPassword(login_email.getText().toString(), login_pwd.getText().toString(), new Firebase.AuthResultHandler() {
  @Override
  public void onAuthenticated(AuthData authData) {
      System.out.println("User ID: " + authData.getUid() + ", Provider: " + authData.getProvider());
      Toast.makeText(getBaseContext(), "Login success!", Toast.LENGTH_LONG).show(); 
      Intent toMainActivity = new Intent(getApplicationContext(), MainActivity.class);
      startActivity(toMainActivity);  
    }
              @Override
  public void onAuthenticationError(FirebaseError firebaseError) {
                  // there was an error
      System.out.println("ERROR.........................................");
       }
  });
  </code></pre>
  
  <p>Heres a simple scenerio:
  User logs in. (From Login class is being Intent to Main activity class)
  User does not log out but delete app's process.
  Later User decides to use the app.</p>
  
  <p>My problem: When click on app, it brings the user back to the Login page whereas it should brought the user to the Main Activity page.</p>
  
  <p><strong>Updated - Initialization</strong></p>
  
  <p>I have initialize it's still not saving the logged in state. </p>
  
  <blockquote>
    <p>My problem: When click on app, it brings the user back to the Login page whereas it should brought the user to the Main Activity page.</p>
  </blockquote>
  
  <p>Here's the Main Activity page:</p>
  
  <pre><code>    protected void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      Firebase.setAndroidContext(this);
  
      setContentView(R.layout.activity_main);
      Firebase user_data = new Firebase("https://myapp.firebaseio.com"); 
      user_data.addAuthStateListener(new Firebase.AuthStateListener() {
          @Override
          public void onAuthStateChanged(AuthData authData) {
              if (authData != null) {
                  System.out.println("Authentication is currently working"); //this did print
              } else {
                  System.out.println("Failed authentication");
              }
          }
      });
  
      AuthData authData = user_data.getAuth();
      if (authData != null) {
          System.out.println("The state is: " + authData); //this did print
      } else {
          System.out.println("Failed");
      }
  </code></pre>
  
  <p>I check the authentication and they seem to be fine but when I delete the process after logging in at the Main Activity it jumps back to the Login page when I reload the app.</p>
  
  <p>The results for monitoring the auth data above:</p>
  
  <p>working auth</p>
  
  <blockquote>
    <p>Authentication is currently working</p>
  </blockquote>
  
  <p>state</p>
  
  <blockquote>
    <p>The state is: AuthData{uid='simplelogin:3', provider='password', token='***', expires='1426758087', auth='{provider=password, uid=simplelogin:3}', providerData='{email=du16493@gmail.com, isTemporaryPassword=false}'}</p>
    
    <p>Authentication is currently working</p>
  </blockquote>
  
  <p><strong>SOLVED</strong></p>
  
  <p>Just add the intent if authentication is currently running and it should straight back into the Main activity when the app first loads up on your phone at your first activity you called.</p>
  
  <p>Here's the Login Activity page:</p>
  
  <pre><code>    protected void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      Firebase.setAndroidContext(this);
  
      setContentView(R.layout.activity_main);
      Firebase user_data = new Firebase("https://myapp.firebaseio.com"); 
      user_data.addAuthStateListener(new Firebase.AuthStateListener() {
          @Override
          public void onAuthStateChanged(AuthData authData) {
              if (authData != null) {
                  System.out.println("Authentication is currently working"); //this did print
                  Intent toMainActivity = new Intent( getBaseContext(), MainActivity.class);
                  startActivity(toMainActivity);
              } else {
                  System.out.println("Failed authentication");
              }
          }
      });
  
      AuthData authData = user_data.getAuth();
      if (authData != null) {
          System.out.println("The state is: " + authData); //this did print
      } else {
          System.out.println("Failed");
      }
  </code></pre>