您应该将其保存在一个文件中,我建议使用SharedPreferences
,然后在每次启动应用程序时从那里读取它,并查看匹配是否正确。
要保存它:
SharedPreferences sp = context.getSharedPreferences("loginSaved", Context.MODE_PRIVATE);
SharedPreferences.Editor editor = sp.edit();
editor.putString("username", "some user value");
editor.putString("password", "some password value");
editor.commit();
为拿到它,为实现它:
SharedPreferences sp = context.getSharedPreferences("loginSaved", Context.MODE_PRIVATE);
String username = sp.getString("username", null);
String password = sp.getString("password", null);
if(username != null && password != null){
// login automatically with username and password
}
else{
// login for the first time
}