title: How to use shared preference to checkbox - Android Studio
body: <p>I created a login page that connects to a mysql database. 
  In the activity_user_login.xml I entered 2 editText for email and password and a login Botton, I added a checkbox for the saved data. 
  I would like to save email and password.<br>
  However, I can not add the sharedPreference. 
  Below the full code.. You can help me? Thank you</p>
  
  <p>activity_user_login.xml    </p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
      xmlns:tools="http://schemas.android.com/tools"
      android:id="@+id/activity_user_login"
      android:layout_width="match_parent"
      android:layout_height="match_parent"
      tools:context="com.myapp.UserLoginActivity"
      android:background="#FF5722"
      android:padding="20dp"&gt;
  
      &lt;TextView
          android:text="User Login Form"
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"
          android:layout_alignParentTop="true"
          android:layout_centerHorizontal="true"
          android:id="@+id/textView"
          android:gravity="center"
          android:textSize="20dp"
          android:textColor="#fff"/&gt;
  
      &lt;EditText
          android:layout_width="fill_parent"
          android:layout_height="50dp"
          android:background="#fbfefd"
          android:inputType="textPersonName"
          android:ems="10"
          android:layout_below="@+id/textView"
          android:layout_centerHorizontal="true"
          android:layout_marginTop="20dp"
          android:id="@+id/email"
          android:hint="Enter Your Email Here"
          android:gravity="center"
          /&gt;
  
      &lt;EditText
          android:layout_width="fill_parent"
          android:layout_height="50dp"
          android:background="#fbfefd"
          android:inputType="textPassword"
          android:ems="10"
          android:layout_below="@+id/email"
          android:layout_centerHorizontal="true"
          android:layout_marginTop="20dp"
          android:id="@+id/password"
          android:hint="Enter Your Password Here"
          android:gravity="center"/&gt;
  
      &lt;Button
          android:text="Log In Here"
          android:layout_width="fill_parent"
          android:layout_height="wrap_content"
          android:layout_below="@+id/password"
          android:layout_centerHorizontal="true"
          android:layout_marginTop="20dp"
          android:id="@+id/Login" /&gt;
  
      &lt;CheckBox
          android:id="@+id/saveLoginCheckBox"
          android:layout_width="fill_parent"
          android:layout_height="wrap_content"
          android:layout_alignParentLeft="true"
          android:layout_below="@+id/editTextPassword"
          android:text="Save Login?"
          android:textColor="#FFF" /&gt;
  
  &lt;/RelativeLayout&gt;  
  </code></pre>
  
  <p>UserLoginActivity.java</p>
  
  <pre><code>package com.myapp.myappcode;
  
  import android.app.ProgressDialog;
  import android.content.Intent;
  import android.os.AsyncTask;
  import android.support.v7.app.AppCompatActivity;
  import android.os.Bundle;
  import android.text.TextUtils;
  import android.view.View;
  import android.widget.Button;
  import android.widget.EditText;
  import android.widget.Toast;
  import java.util.HashMap;
  
  
  public class UserLoginActivity extends AppCompatActivity {
  
      EditText Email, Password;
      Button LogIn ;
      String PasswordHolder, EmailHolder;
      String finalResult ;
      String HttpURL = "http://mysite/User/UserLogin.php";
      Boolean CheckEditText ;
      ProgressDialog progressDialog;
      HashMap&lt;String,String&gt; hashMap = new HashMap&lt;&gt;();
      HttpParse httpParse = new HttpParse();
      public static final String UserEmail = "";
  
      @Override
      protected void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.activity_user_login);
  
          Email = (EditText)findViewById(R.id.email);
          Password = (EditText)findViewById(R.id.password);
          LogIn = (Button)findViewById(R.id.Login);
  
          LogIn.setOnClickListener(new View.OnClickListener() {
              @Override
              public void onClick(View view) {
  
                  CheckEditTextIsEmptyOrNot();
  
                  if(CheckEditText){
  
                      UserLoginFunction(EmailHolder, PasswordHolder);
  
                  }
                  else {
  
                      Toast.makeText(UserLoginActivity.this, "Please fill all form fields.", Toast.LENGTH_LONG).show();
  
                  }
  
              }
          });
      }
      public void CheckEditTextIsEmptyOrNot(){
  
          EmailHolder = Email.getText().toString();
          PasswordHolder = Password.getText().toString();
  
          if(TextUtils.isEmpty(EmailHolder) || TextUtils.isEmpty(PasswordHolder))
          {
              CheckEditText = false;
          }
          else {
  
              CheckEditText = true ;
          }
      }
  
      public void UserLoginFunction(final String email, final String password){
  
          class UserLoginClass extends AsyncTask&lt;String,Void,String&gt; {
  
              @Override
              protected void onPreExecute() {
                  super.onPreExecute();
  
                  progressDialog = ProgressDialog.show(UserLoginActivity.this,"Loading Data",null,true,true);
              }
  
              @Override
              protected void onPostExecute(String httpResponseMsg) {
  
                  super.onPostExecute(httpResponseMsg);
  
                  progressDialog.dismiss();
  
                  if(httpResponseMsg.equalsIgnoreCase("Data Matched")){
  
                      finish();
  
                      Intent intent = new Intent(UserLoginActivity.this, DashboardActivity.class);
  
                      intent.putExtra(UserEmail,email);
  
                      startActivity(intent);
  
                  }
                  else{
  
                      Toast.makeText(UserLoginActivity.this,httpResponseMsg,Toast.LENGTH_LONG).show();
                  }
  
              }
  
              @Override
              protected String doInBackground(String... params) {
  
                  hashMap.put("email",params[0]);
  
                  hashMap.put("password",params[1]);
  
                  finalResult = httpParse.postRequest(hashMap, HttpURL);
  
                  return finalResult;
              }
          }
  
          UserLoginClass userLoginClass = new UserLoginClass();
  
          userLoginClass.execute(email,password);
      }
  
  }
  </code></pre>