i am making an application in which i want to implement login. i am saving user password in SharedPreference
, it stored properly and works well. but when i force close the application the preference key got cleared. i am saving the key in the following code when user press the okey button.
case R.id.bOkey:
if (sp.contains(KEY_PASSWORD)) {
Toast.makeText(getApplicationContext(), "contains the key", Toast.LENGTH_LONG).show();
if (sp.getString(KEY_PASSWORD, null).equals(etPassword.getText().toString())) {
Toast.makeText(getApplicationContext(), "Login Success", Toast.LENGTH_LONG).show();
}else{
Toast.makeText(getApplicationContext(), "Login Failed", Toast.LENGTH_LONG).show();
}
}else{
Toast.makeText(getApplicationContext(), "Does not contains the key", Toast.LENGTH_LONG).show();
sp.edit().putString(KEY_PASSWORD, etPassword.getText().toString()).commit();
}
break;
Thanks in Advance!! -Usman Riaz-