简体   繁体   中英

Manage User Sessions of two type of (Student and Teacher) in an android app using fire base

管理学生和教师等两种不同类型用户的用户会话,以便他们在不注销的情况下退出应用程序时保持登录状态

You can create an AppPreference class and create a session for your user type and set you user type like Student and teacher:

public class AppPrefrences {
    private static SharedPreferences mPrefs;
    private static SharedPreferences.Editor mPrefsEditor;

   public static String getUserType(Context ctx) {
        mPrefs = PreferenceManager.getDefaultSharedPreferences(ctx);
        return mPrefs.getString("UserType", "");
    }

    public static void setUserType(Context ctx, String value) {
        mPrefs = PreferenceManager.getDefaultSharedPreferences(ctx);
        mPrefsEditor = mPrefs.edit();
        mPrefsEditor.putString("UserType", value);
        mPrefsEditor.commit();
    }
}

set the values when you logged in your app like this:-

if userType is Teacher:

setUserType(this, "Teacher");

or if userType is Student:

setUserType(this, "Student");

and get your logged in user type where you need:

String userType = getUserType(this);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM