title: onViewStateRestored crashing android app
body: <p>I am a beginner in Android development. I wanted to save user login data so that he doesnt have to login after pausing and resuming the app or when he uses the app again. After going through some posts on stackoverflow, I realised onSavedInstance is the way to do it.</p>
  
  <p>I have implemented the methods in one loginActivity but the app gives an error when i open this activity on the emulator.
  the error is <strong>Unfortunately, 'Project_name' has stopped</strong></p>
  
  <p>So, I checked the log files, and got this</p>
  
  <p><strong>java.lang.NullPointerException: Attempt to invoke virtual method 'boolean android.os.Bundle.getBoolean(java.lang.String)' on a null object reference</strong></p>
  
  <p>on the line </p>
  
  <p>boolean inSession = savedInstanceState.getBoolean("loggedin"); </p>
  
  <p>in the onViewStateRestored method.</p>
  
  <p>Can someone help me find out where am i going wrong and Is there any better way to store login details so that user doesn't have to log in everytime the app goes in pause or stop mode?</p>
  
  <p>Thanks for the help in advance. :)</p>
  
  <pre><code> @Override
  public void onSaveInstanceState(Bundle savedInstanceState) {
      super.onSaveInstanceState(savedInstanceState);
      if(inSession){
          savedInstanceState.putBoolean("loggedin",true);
          savedInstanceState.putString("email",emailcol);
          savedInstanceState.putString("password",passwordcol);
          savedInstanceState.putString("type","login");
      }
      else{
          savedInstanceState.putBoolean("loggedin",false);
  
      }
  }
  
  @Override
  public void onViewStateRestored(Bundle savedInstanceState) {
      super.onViewStateRestored(savedInstanceState);
  
          boolean inSession = savedInstanceState.getBoolean("loggedin");
          if (inSession) {
              String email = savedInstanceState.getString("email");
              String pass = savedInstanceState.getString("password");
              String type = "login";
              BackgroundWorker bw = new BackgroundWorker(this.getContext());
              //(Name,password,email,contact,address,type
              bw.execute(null, pass, email, null, null, type);
          }
  
  }
  </code></pre>