Search code examples
androidauthenticationsession-management

How to login one time in android application?


I am allowing registered users to access the app. The users have to login every time they open the app. So I want to know how to login the app single time like facebook or whatsapp?


Solution

  • You can use Shared Preferences .

    Android provides many ways of storing data of an application. One of this way is called Shared Preferences. Shared Preferences allow you to save and retrieve data in the form of key,value pair.

    SO Help .

    • You can save and retrieve key, value pair data from Shared preferences. SharedPreferences values will persist across user sessions.
    • Data in shared preferences will be persistent even though user closes the application.
    • You can get values from Shared preferences using getSharedPreferences() method.

    • You also need an editor to edit and save the changes in shared preferences.

    • Use SharedPreferences to store data: booleans, floats, ints, longs, and strings.

    Demo

    1. Android User Session Management using Shared Preferences
    2. Android Working with Shared Preferences