I have made an android app which working fine. I implemented the Login functionality in it. Can anyone guide me how to store the login credentials of the user so that the user does not have to login everytime he/she starts the app and when user logout then clear the stored login information.
Actually i want that user does not have to enter login information everytime when he/she starts the app.How can i do this?
In general sensitive data stored locally on the device should always be at least encrypted, and any keys used for encryption methods should be securely stored within the Android Keystore. These files should also be stored within the application sandbox.
Store value use sharepreference. i am pasting code here..use it.
Create Share Preference:
SharedPreferences sp=getSharedPreferences("Login", MODE_PRIVATE);
SharedPreferences.Editor Ed=sp.edit();
Ed.putString("Unm",Value );
Ed.putString("Psw",Value);
Ed.commit();
Get Value from Share preference:
SharedPreferences sp1=this.getSharedPreferences("Login", MODE_PRIVATE);
String unm=sp1.getString("Unm", null);
String pass = sp1.getString("Psw", null);
When user logout then you can set null value into sharedpreference.
I think the best solution is Shared Preference. It is useless to create a whole Database and query it, for just one entry. And File System doesnt provide a structured solution. (key value pairs)
For UI, I think that you should have two Fragments
if the user is registered show him The MainFragment
and if not the LoginFragment
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With