Skip to content
Advertisement

Android – Keep user logged in

I’m trying to make a login with PHP and MySQLi for Android. What I don’t understand is how to keep the user logged in? I saw a simple tutorial where someone used SQLite to safe information but I’m not aware if that is really secure way. How should I save the user information to keep the users logged in?

Thank you.

Advertisement

Answer

Use the SharedPreferences in android

when your loggedin store the data using

SharedPreferences pref = getApplicationContext().getSharedPreferences("MyPref", 0); // 0 - for private mode
Editor editor = pref.edit();
//on the login store the login
editor.putLong("key_name", "long value"); 
editor.commit();

retrieves the data of the key

pref.getString("key_name", "");
                            ^
   default value if the user is not loggedin

clear the data when logout

editor.remove("name");
editor.commit();

Refer this Link for More

User contributions licensed under: CC BY-SA
6 People found this is helpful
Advertisement