I have a Log In activity for my app and I would like to "lock" the user out after a certain number of attempts. I would like to store my int counter in the sharedpreferences but I'm unsure as to how to set a timer for it to restore in the preferences. Here is my code for the log in.
login_Button.setOnClickListener(new View.OnClickListener(){
@Override
public void onClick(View v) {
int uid = 1155;
String pass = "pass";
SharedPreferences userDetails = getSharedPreferences(User_File, MODE_PRIVATE);
SharedPreferences.Editor edit = userDetails.edit();
edit.putInt("userID", uid);
edit.putString("password", pass);
edit.commit();
if((etUserID.getText().toString().equals(""))){
Toast.makeText(getApplicationContext(),"Please enter a User ID", Toast.LENGTH_LONG).show();
}else if (etPassword.getText().toString().equals("")){
Toast.makeText(getApplicationContext(),"Please enter a password", Toast.LENGTH_LONG).show();
}else{
String user_id = etUserID.getText().toString();
int user_id2 = Integer.parseInt(user_id);
String user_password = etPassword.getText().toString();
int userID = userDetails.getInt("userID", 1);
String password = userDetails.getString("password", "no name");
if (userID == user_id2 && password.equals(user_password)){
startActivity(new Intent(LogOn.this,CrimeMap.class));
}else{
counter = counter - 1;
Toast.makeText(getApplicationContext(), "You have" + counter + "attempts remaining", Toast.LENGTH_LONG).show();
if(counter == 0){
}
}
}
}
});