如何使用共享首选项创建多会话,以便两个用户可以在同一会话中登录和注销?使用SharedPreferences登录很多用户
我有以下代码。
public class Session
{
SharedPreferences prefs;
SharedPreferences.Editor editor;
Context ctx;
String [][] usuarios;
int i,j;
public Session(Context ctx)
{
this.ctx = ctx;
prefs = ctx.getSharedPreferences("init", Context.MODE_PRIVATE);
editor = prefs.edit();
}
public void setLoggedIn(boolean loggedin)
{
editor.putBoolean("loggedinmode",loggedin);
editor.commit();
}
public boolean loggedin()
{
return prefs.getBoolean("loggedinmode",false);
}
}
我正在使用Android Studio。
两个用户最大?或者任何数字?此外,SharedPreferences不是存储列表的好方法,更好的解决方案是使用JSON或纯文本文件。 –