title: check shared preference value
body: <p>I want to check the value in <code>editext</code> every time app is launched. I'm using shared preference to store <code>edittext</code> value user entered the first time app was launched. The next time app is launched if the value in <code>edittext</code> is same as saved shared preference value then instead of showing that activity, app skips it and displays the next activity. Prob is even if the value is correct in  <code>edittext</code>, app is not skipping that activity. I think the comparing values might be incorrect.</p>
  
  <p><strong>MainActivity</strong></p>
  
  <pre><code>public class LoginActivity extends Activity{
  
      EditText et;
      int keyDel;
      String tempString;
      char[] stringArray;
  
      SharedPreferences sharedpreferences;
      public static final String mypreference = "mypref";
      public static final String PIN = "passKey";
  
      @Override
      protected void onCreate(Bundle savedInstanceState) {
          // TODO Auto-generated method stub
          super.onCreate(savedInstanceState);
          setContentView(R.layout.loginactivity);
  
          et = (EditText)findViewById(R.id.editText1);
  
  ///////////////////////////////////// Shared Preference Code Starts /////////////////////////////////////////////////////////////////////////
          sharedpreferences = getSharedPreferences(mypreference, Context.MODE_PRIVATE);
          if (sharedpreferences.contains(PIN)) {
              et.setText(sharedpreferences.getString(PIN, ""));
          }
  
          String chk_et = et.getText().toString();
          if(chk_et == sharedpreferences.getString(PIN, "")){
              startActivity( new Intent(LoginActivity.this, Welcome.class));
              finish();
  
              //finish();
          }else{
              Toast.makeText(getApplicationContext(), "Wrong Details", Toast.LENGTH_SHORT).show();
  
          } 
  
  ///////////////////////////////////// Shared Preference Code Ends ///////////////////////////////////////////////////////////////////////////   
  
  ///////////////////////////////////// Text Watcher Code Starts //////////////////////////////////////////////////////////////////////////////
          et.addTextChangedListener(new TextWatcher() {
  
              @Override
              public void beforeTextChanged(CharSequence s, int start, int count,
                      int after) {
                  // TODO Auto-generated method stub
  
              }
  
              @Override
              public void onTextChanged(CharSequence s, int start, int before,
                      int count) {
                  // TODO Auto-generated method stub
                   et.setOnKeyListener(new OnKeyListener() {
                          @Override
                          public boolean onKey(View v, int keyCode, KeyEvent event) {
  
                                if(keyCode != KeyEvent.KEYCODE_DEL &amp;&amp; et.getText().length() !=0)
                                  {
                                      if(et.getText().length()==4 ||et.getText().length()==8)
                                      {                             
                                          tempString=et.getText().toString()+"-";
                                          char c=tempString.charAt(tempString.length()-2);
  
                                          if(c!='-')
                                          {
                                              stringArray = tempString.toCharArray();                    
                                              stringArray[tempString.length()-2]=stringArray[tempString.length()-1];
                                              stringArray[tempString.length()-1]=c;
  
                                              //code to convert charArray back to String..
                                              tempString=new String(stringArray);
                                              et.setText(tempString);             
                                              et.setSelection(tempString.length());
                                              tempString=null;
                                          }
  
                                      }
                                  }
  
                                  return false ;   
                          }
                      });
  
  
              }
  
              @Override
              public void afterTextChanged(Editable s) {
                  // TODO Auto-generated method stub
  
              }
  
          });
  
  ///////////////////////////////////// Text Watcher Code Ends //////////////////////////////////////////////////////////////////////////////     
      } // onCreate ends
  
      public void Save(View view) {
          String et_new = et.getText().toString();
          Editor editor = sharedpreferences.edit();
          editor.putString(PIN, et_new);
          editor.commit();
      }
  
  } // Activity ends  
  </code></pre>