Skip to content Skip to sidebar Skip to footer

Sharedpreferences In Android App For Remember Me Button

Im not to sure what I'm doing wrong. In my app I'm trying to have it remember a previous password entered into the textfield on submit. From research done using shared preferences

Solution 1:

use this code to get SharedPreference in fragment

SharedPreferencespreferences=this.getActivity().getSharedPreferences("myPref", Context.MODE_PRIVATE);

Solution 2:

do you define the context?

Context context;

i didnt see the value of context here. maybe this is the reason why its return NullPointerException you should define it with activity or context. And you can also do this instead make context var: getApplicationContext().getSharedPreferences() Or getActivity().getSharedPreferences()

Solution 3:

try

Contextcontext= getApplicationContext();
SharedPreferencessettings= context.getSharedPreferences(PASSVALUE, context.MODE_PRIVATE);

You're getting NullPointerException because context is undefined. Either define it before calling your context.getSharedPreference() or use another way such as getApplicationContext().getSharedPreference() .

Post a Comment for "Sharedpreferences In Android App For Remember Me Button"