Login for Android applications

There are several applications that require a login. Can I find out how the application manages a user's session on Android? For example, as soon as the user logs into the application, the next time the user launches the application, he will directly go to the home page, and not to the login page. Although if the user starts the application for the first time or before logging in, the application will start from the login page. Can a telephone keypad handle this? Thank.

+3
source share
3 answers

Depending on which version of Android you are planning and which version of PhoneGap you are using, you should use one of the built-in offline storage mechanisms available in the browser. These include localStorage and WebKitSQLite.

There is also a fantastic open source library in which you can use the abbreviations of any particular autonomous storage engine and allow interchangeable base storage adapters and provide a single unified key / value for the interface. The library is called Lawnchair - check it out!

So, at boot you should create an instance of Lawnchair and see if your saved user settings exist:

function onLoad() {
    myStore = new Lawnchair();
    myStore.get('login', function(i) {
        if (i == null) {
            // user did not login before, no saved credentials.
        } else {
            // user DID login, we can now auto-login for the user.
        }
    });
}

, Lawnchair, , PhoneGap :

function login(username, password) {
    /* 
     * Do the login stuff here
     */
    if (/* login was successful */) {
        myStore.save({key:'login',value:{username:username, password:password}});
    } else {
        alert('Could not log you in!');
    }
}

, , - get() key , save(). , .

, !

+3

.

SharedPreferences settings = .getSharedPreferences("some_key, MODE_PRIVATE);
        SharedPreferences.Editor editor = settings.edit();
        editor.putString("token", "123456");
        editor.commit();

, , , . , .

0

I do not know what phonegap is, but I think that usually applications simply store the login somewhere in general preferences . So, all you need to do is check at startup if there are certain preferences. If there are none, you must specify the login page.

-1
source

Source: https://habr.com/ru/post/1785284/


All Articles