我正在尝试检查用户之前是否已登录,使用Parse,如果有,则应将它们带到MainForm,但如果没有,则应将用户带到LoginForm。
ParseUser currentUser = ParseUser.getCurrent();
if (currentUser != null) {
new MainForm(theme).show();
} else {
new LoginForm(theme).show();
}
但它给了我错误,我不知道我做错了什么,请帮忙。
答案 0 :(得分:3)
您是否考虑过将用户信息保存到首选项中?
来自聊天应用演示项目:https://www.codenameone.com/blog/building-a-chat-app-with-codename-one-part-2.html
// if the user already logged in previously and we have a token
String t = Preferences.get(tokenPrefix + "token", (String)null);
if(t != null) {
// we check the expiration of the token which we previously stored as System time
long tokenExpires = Preferences.get(tokenPrefix + "tokenExpires", (long)-1);
if(tokenExpires < 0 || tokenExpires > System.currentTimeMillis()) {
// we are still logged in
showContactsForm(data);
return;
}
}