Search code examples
javaandroidandroid-layoutlocal-storagesharedpreferences

how to check stored value using shared preferences in android?


I have one text box in SignUp layout and one text box in logIn layout. Now how to validate text box value using shared preferences in android?


Solution

  • Simple..

    Considering signupText, loginText as object.

    1. Store sign up text in preference. I have used a separate class for preference. For more how to write preference in separate class and use it means, please refer here for preference..

    store signupText in preference.

    mPreferenceData.storeInPreference("signup",     
    signupText.getText().toString().trim()));
    

    in login page

    String signUpText = mPreferenceData.getStoreInPreference("signup");
    //now you will have data in signupText
    button.setOnClickListener(new View.OnClickListener(){        
        if(loginText.getText().toString().trim().equalsIgnoreCase(signUpText)){
            // now loginText whatever data that matches with signUpText will make to login successful
        } else{
            //failure
        }
    
    });