I have to activities that I'm working with. A login screen and a sign up screen. I save my data in the sign up screen then go back to the login screen and type in my user name and password but it keeps bringing up an error message I coded saying no user is found.
Code for sign up activity:
protected override void OnCreate (Bundle bundle)
{
base.OnCreate (bundle);
SetContentView (Resource.Layout.SignUp);
var txtUserName = FindViewById<EditText> (Resource.Id.txtUserName);
var txtPassword = FindViewById<EditText> (Resource.Id.txtPassword);
var txtConfirmPassword = FindViewById<EditText> (Resource.Id.txtConfirmPass);
var btnSubmit = FindViewById<Button> (Resource.Id.btnSubmit);
btnSubmit.Click += delegate (Object sender,EventArgs e)
{
if (Validator.IsPresent(txtUserName, "Username",this) && Validator.IsPresent(txtPassword,"Password",this) && Validator.IsPresent(txtConfirmPassword,"Confirm password",this))
{
ISharedPreferences sharedPref = GetPreferences(FileCreationMode.Private);
ISharedPreferencesEditor editor = sharedPref.Edit();
string userKey = "user" +txtUserName.Text.Trim().ToUpper();
string userPass = "pass" + txtUserName.Text.Trim().ToUpper();
editor.PutString(userKey,txtUserName.Text);
editor.PutString(userPass,txtPassword.Text);
editor.Apply();
if (editor.Commit() == false)
{
AlertDialog.Builder msgSignupFail = new AlertDialog.Builder(this);
msgSignupFail.SetTitle("Sign Up Failed");
msgSignupFail.SetMessage("Your sign up has failed. Please try again.");
msgSignupFail.Show();
}
}
};
}
Code for Login: protected override void OnCreate (Bundle bundle) { base.OnCreate (bundle);
SetContentView (Resource.Layout.Login);
// Create your application here
var btnLogin = FindViewById<Button> (Resource.Id.btnLogin);
var txtUserName = FindViewById<EditText> (Resource.Id.txtUserName);
btnLogin.Click += delegate(object sender, EventArgs e) {
ISharedPreferences sharedPref = GetPreferences (FileCreationMode.Private);
string user = "user" + txtUserName.Text.Trim().ToUpper();
String userName = sharedPref.GetString(user,null);
if (userName != null)
{
AlertDialog.Builder msgLoggingIn = new AlertDialog.Builder(this);
msgLoggingIn.SetTitle("Logging In");
msgLoggingIn.SetMessage("Logging in as " + txtUserName.Text);
msgLoggingIn.Show();
msgLoggingIn.Dispose();
}
else {
AlertDialog.Builder msgNoLogin = new AlertDialog.Builder (this);
msgNoLogin.SetTitle (this.GetString (Resource.String.ttlNoUserFound));
msgNoLogin.SetMessage (this.GetString (Resource.String.msgNoUserFound));
msgNoLogin.SetNegativeButton ("Close", (s, ev) => {
msgNoLogin.Dispose ();
});
msgNoLogin.Show ();
}
};
var btnSignUp = FindViewById<Button> (Resource.Id.btnSignup);
btnSignUp.Click += delegate(object sender, EventArgs e)
{
StartActivity(typeof(SignUp));
};
}
I do have the checkbox checked that makes sure data/cache is saved