[Solved] how to make auto login in android with sql database [closed]


may be you are trying to say that when you close the app user don’t have to enter the login credentials again ,what you say is auto login, for this.
use shared preferences and session manager in android

steps:-

  • in your login page do check this following condition

    session = new SessionManager(getApplicationContext());
    
    // Check if user is already logged in or not
    if (session.isLoggedIn()) {
        // User is already logged in. Take him to main activity
        Intent intent = new Intent(LoginActivity.this, MainActivity.class);
        startActivity(intent);
        finish();
    }
    

and then clear the session on logout

if (id == R.id.action_logout) {
        //clearing the stored sessions
        session.setLogin(false);
        Intent intent = new Intent(this.getApplicationContext(), LoginActivity.class);
        intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK);
        startActivity(intent);
        return true;
    }

here is session manager looks like in mine case

package com.vikaskumar.materialdesign.helper;
import android.content.Context;
import android.content.SharedPreferences;
import android.content.SharedPreferences.Editor;
import android.util.Log;
public class SessionManager {
    // Shared preferences file name
    private static final String PREF_NAME = "PrefName";
    private static final String KEY_IS_LOGGEDIN = "isLoggedIn";
    private static final String NAME = "name";
    private static final String EMAIL = "email";
    private static final String FLAG = "flag";
    // LogCat tag
    private static String TAG = SessionManager.class.getSimpleName();
    // Shared Preferences
    SharedPreferences pref;
    Editor editor;
    Context _context;
    // Shared pref mode
    int PRIVATE_MODE = 0;

    public SessionManager(Context context) {
        this._context = context;
        pref = _context.getSharedPreferences(PREF_NAME, PRIVATE_MODE);
        editor = pref.edit();
    }

    public void setLogin(boolean isLoggedIn) {

        editor.putBoolean(KEY_IS_LOGGEDIN, isLoggedIn);

        // commit changes
        editor.commit();

        Log.d(TAG, "User login session modified!");
    }

    public void setUserFlag(String flag) {
        editor.putString(FLAG, flag);
        editor.commit();
    }

    public String getUserEmail() {
        return pref.getString(EMAIL, null);
    }

    public void setUserEmail(String email) {
        editor.putString(EMAIL, email);
        editor.commit();
    }

    public String getFLAG() {
        return pref.getString(FLAG, null);
    }

    public String getUserName() {
        return pref.getString(NAME, null);
    }

    public void setUserName(String name) {
        editor.putString(NAME, name);
        editor.commit();
    }

    public boolean isLoggedIn() {
        return pref.getBoolean(KEY_IS_LOGGEDIN, false);
    }
}

i just hope this helps you ,a good tutorials is here
tutorial

solved how to make auto login in android with sql database [closed]