I have an application in which I have to implement a "Login" activity. I have these components:
- EditText username
- EditText password
- Button Login
- Button Cancel
I want that my application to remember the login details of the user once the user has logged in until the user would press the "log out" button. I'm not using preferences in my xml.
How do I get the getSharedPreferences(String name, int mode) to work in my application?
After reading around alot, only this worked: In class to set Shared preferences:
In AlarmReciever:
First get the instance of SharedPreferences using
Now to save the values in the SharedPreferences
Above lines will write username and password to preference
Now to to retrieve saved values from preference, you can follow below lines of code
(NOTE: SAVING PASSWORD IN THE APP IS NOT RECOMMENDED. YOU SHOULD EITHER ENCRYPT THE PASSWORD BEFORE SAVING OR SKIP THE SAVING THE PASSWORD)
Try this..