title: Saving login credentials(username and password) through remember me checkbox
body: <p>I'm new to android and using Remember me checkbox for saving username name and password for the first time in my application. I have tried lots of code and did R &amp; D for this function on Google but didn't succeed. In this app, the username(studentId) an password is fetched from server. I'll be thankful if some one help me in this. Thanks in </p>
  
  <p>Here is my code:</p>
  
  <pre><code>public class LoginActivityB extends Activity {
  
  String studentID, password;
  TextView errorTV;
  
  private CheckBox saveLoginCheckBox;
  private Boolean saveLogin,saveAuth;
  LoginDataBaseAdapter dbase;
  private Handler handler;
  EditText editTextUserName, editTextRe_enterPassword;
  private SharedPreferences loginPreferences;
  private SharedPreferences.Editor loginPrefsEditor;
  
  @SuppressLint("NewApi")
  @Override
  protected void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      this.requestWindowFeature(Window.FEATURE_NO_TITLE);
      setContentView(R.layout.activity_login_activity_b);
      ImageView btnSignIn = (ImageView) findViewById(R.id.buttonSignIn);
      loginPreferences = getSharedPreferences("loginPrefs", MODE_PRIVATE);
      loginPrefsEditor = loginPreferences.edit();
      saveLogin = loginPreferences.getBoolean("saveLogin", false);
      saveAuth = loginPreferences.getBoolean("saveAuth", false);
  
     dbase = new LoginDataBaseAdapter(LoginActivityB.this);
      editTextUserName = (EditText) findViewById(R.id.editID);
      editTextRe_enterPassword = (EditText) findViewById(R.id.editTextPassword);
      editTextRe_enterPassword.setVisibility(View.GONE);
      final EditText editTextPassword = (EditText) findViewById(R.id.editPassword);
      TextView forgotPasswordTV = (TextView) findViewById(R.id.forgotPasswordTV);
      saveLoginCheckBox = (CheckBox) findViewById(R.id.rememberMeCB);
      errorTV = (TextView) findViewById(R.id.errorTV);
  
      if (saveLogin == true) {
          saveLoginCheckBox.setChecked(true);
          Intent dashboard = new Intent(getApplicationContext(),
                  DashboardActivity.class);
          startActivity(dashboard);
          finish();
      }
  
      btnSignIn.setOnClickListener(new View.OnClickListener() {
  
          public void onClick(View v) {
              studentID = editTextUserName.getText().toString();
              password = editTextPassword.getText().toString();
              String reEnterPassword = editTextRe_enterPassword.getText()
                      .toString();
  
              new AsyncCaller().execute();
              stopNewService();
              startNewService();
          }
      });
  
     public void startNewService() {
      startService(new Intent(this, com.education.service.MyService.class));
      }
  
  public void stopNewService() {
  
      stopService(new Intent(this, com.education.service.MyService.class));
      }
  public void connection() {
          final AsyncHttpClient myClient = new AsyncHttpClient();
          myClient.setTimeout(60000);
          myClient.addHeader("Content-type",
                  "application/x-www-form-urlencoded");
          myClient.addHeader("X_MOBICOACH_KEY", "MOBICOACH2013");
          RequestParams params = new RequestParams();
          params.put("studentid", studentID);
          params.put("password", password);
          params.put("stream", "engg");
  
          myClient.post(Config.urlPath + "/SaveData", params,
                  new AsyncHttpResponseHandler() {
  
                      @Override
                      public void onSuccess(String response) {
                          System.out.println(response);
                          if (response != null) {
                              if (response.contains("OK")) {
                                  String userID = response.substring(3);
                                  // String ID = removeLastChar(userID);
  
                                  dbase.deleteAll();
                                  dbase.insertEntry(studentID, password,
                                          userID);
  
                                  if (saveLoginCheckBox.isChecked()) {
  
                                  loginPrefsEditor.putBoolean("saveLogin", true);
                                  loginPrefsEditor.putString("username", studentID);
                                  loginPrefsEditor.putString("password", password);
                                  loginPrefsEditor.putString("value", "1");
                                  loginPrefsEditor.putString("userID", userID);
                                  loginPrefsEditor.commit();
  
                                    } else { 
                                        loginPrefsEditor.clear();
                                        loginPrefsEditor.commit(); }
  
  
                                  Intent dashboard = new Intent(
                                          getApplicationContext(),
                                          DashboardActivity.class);
                                  startActivity(dashboard);
                                  finish();
  
                              }
                          }
    }
  </code></pre>