title: Shared Preferences doesn't seem to save username in session
body: <p>For a few days, I have been trying to get the username to save in session properly. First, I opened the app and it would open login screen. I login with username, then it would take me to the MainActivity. Now I exit the app and reopen the app to ensure that username is saved and it would pass the login screen and go straight to the MainActivity. So far so good, then I would logout and it would go back to the login screen. I want to make sure that it is completely logged out so i exit the app and reopen the app and it would take me to the MainActivity. I couldn't figure out how to fix that problem. </p>
  
  <p>my login class </p>
  
  <pre><code>public void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.login);
  
          SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(getApplicationContext());
          SharedPreferences.Editor editor = prefs.edit();
          editor.putString("username", username);
          editor.commit();
  
  
          if(prefs.getString("username", null)!=username)
          {Intent i = new Intent(getApplicationContext(), Customer.class); 
          startActivity(i);}
  
  
          etUsername = (EditText)findViewById(R.id.username);
          btnLogin = (Button)findViewById(R.id.login_button);
          btnCancel = (Button)findViewById(R.id.cancel_button);
          lblResult = (TextView)findViewById(R.id.result);
  
          btnLogin.setOnClickListener(new OnClickListener() {
              //@Override
              public void onClick(View v) {
              // Check Login
              String username = etUsername.getText().toString();
  
              if(username.equals("1111")){
                  lblResult.setText("Login successful.");
  
                   Intent i = new Intent(getApplicationContext(), MainActivity.class);
                  startActivity(i);
  </code></pre>
  
  <p>my logout class</p>
  
  <pre><code>public void onCreate(Bundle savedInstanceState) { 
          super.onCreate(savedInstanceState);
          setContentView(R.layout.logout);
  
          code = (EditText)findViewById(R.id.codeout);
          btnLogout = (Button) findViewById(R.id.submit);
          btnCancel = (Button) findViewById(R.id.cancel);
          lblResult = (TextView)findViewById(R.id.result);
  
          btnLogout.setOnClickListener(new OnClickListener(){
  
              @Override
              public void onClick(View v) {
                  // TODO Auto-generated method stub
                  String logout = code.getText().toString();
  
                  if (logout.equals("99")){
                      lblResult.setText("Logout successful");
  
                      SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(getApplicationContext());
  
                      SharedPreferences.Editor editor = prefs.edit();
                      editor.remove("username");
                      editor.commit();
  
                      Intent i = new Intent(getApplicationContext(), Login.class);
                      startActivity(i);
  
                      finish();
  </code></pre>