title: Keep user logged in when app is closed - Android Studio - MySQL
body: <p>I have create an App where a User list for a group is already placed in a database on MySQL, the Usernames, passwords and variables assigned to them are already uploaded. </p>
  
  <p>Below is the login activity that allows a user to log in and go to their own user area (There is a loginrequest class also that brings the params over).</p>
  
  <p>What I need assistance with is making the application stay logged in until logout for that user even when they have closed the app.</p>
  
  <p>Also will this if possible allow me to send user notifications when the app is closed to individual users?</p>
  
  <p>thank you.  </p>
  
  <pre><code>@Override
  protected void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      setContentView(R.layout.activity_login);
  
  
      final EditText etUsername = (EditText) findViewById(R.id.etUsername);
      final EditText etPassword = (EditText) findViewById(R.id.etPassword);
      final Button bLogin = (Button) findViewById(R.id.bLogin);
      final TextView registerLink = (TextView) findViewById(R.id.tvRegisterHere);
  
      //Register Here button
      registerLink.setOnClickListener(new View.OnClickListener() {
          @Override
          public void onClick(View v) {
              Intent registerIntent = new Intent(LoginActivity.this, RegisterActivity.class);
              LoginActivity.this.startActivity(registerIntent);
          }
      });
  
      //Login Button
      bLogin.setOnClickListener(new View.OnClickListener() {
          @Override
          public void onClick(View v) {
              //Taking the username and password and converting it to a string
              final String username = etUsername.getText().toString();
              final String password = etPassword.getText().toString();
              Response.Listener&lt;String&gt; responseListener = new Response.Listener&lt;String&gt;() {
                  @Override
                  public void onResponse(String response) {
                      try {
                          //Taking the JSONObject from the 000webhost database
  
                          JSONObject jsonResponse = new JSONObject(response);
                          //If the response is successful ie is there a username and password that match
                          boolean success = jsonResponse.getBoolean("success");
                          if (success){
                              //Gather the information below
                              String name = jsonResponse.getString("name");
                              int var1 = jsonResponse.getInt("var1");
                              int var2 = jsonResponse.getInt("var2");
                              int var3 = jsonResponse.getInt("var3");
                              int var4 = jsonResponse.getInt("var4");
  
  
  
                              Intent intent = new Intent(LoginActivity.this, UserAreaActivity.class);
                              intent.putExtra("name", name);
                              intent.putExtra("username", username);
                              intent.putExtra("var1", var1);
                              intent.putExtra("var2", var2);
                              intent.putExtra("var3", var3);
                              intent.putExtra("var4", var4);
                              intent.putExtra("password", password);
  
                              //Start the User Area Activity
  
                              LoginActivity.this.startActivity(intent);
  
  
  
  
                          }else{
  
                              AlertDialog.Builder builder = new AlertDialog.Builder(LoginActivity.this);
                              builder.setMessage("Login Failed")
                                      .setNegativeButton("Retry", null)
                                      .create()
                                      .show();
                          }
  
  
                      } catch (JSONException e) {
                          e.printStackTrace();
                      }
                  }
              };
  
  
  
              LoginRequest loginRequest = new LoginRequest(username, password, responseListener);
              RequestQueue queue = Volley.newRequestQueue(LoginActivity.this);
              queue.add(loginRequest);
  
          }
      });
  
  }
  </code></pre>