How to save login information locally in android

I made an android app that works great. I implemented login functions in it. Can someone tell me how to store user credentials so that the user cannot log in every time he launches the application and when the user logs out and then clears the saved registration information.

In fact, I want this user to not have to enter login information every time he starts the application. How can i do this?

+7
source share
4 answers

Use sharepreference. I paste the code here .. use it.

Create rule:

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 the user logs out, you can set the value null to sharedpreference.

+28
source

I believe the best solution is Shared Preference. It is useless to create an entire database and query it in just one record. And the file system does not provide a structured solution. (key value pairs)

For the user interface, I believe that you should have two fragments if the user is registered, show him MainFragment and if not LoginFragment

+1
source

Create an external database file with the credential table in this table, create the appropriate columns, such as username, password, etc., if you registered users, then save the data of these users in the credential table. Finally copy this database to the assests folder, and then use a copy of the SqliteOpenHelper class that is the external database for the phone's memory. You must save the registration page with the conditions. If the user completes the registration procedure with your conditions, save his / her data in the credential table. When a user wants to enter the application, check the username and password in the credential table.

0
source

You can use each of the following methods: - General questions - Database - File system

Of course, each method has pros and cons.

0
source

All Articles