我正在使用android for parse.com。我已成功登录并注册了我的凭据,数据也在我的parse.com表中上传。登录的代码段如下:
loginbutton.setOnClickListener(new OnClickListener() {
public void onClick(View arg0) {
// Retrieve the text entered from the EditText
usernametxt = username.getText().toString();
passwordtxt = password.getText().toString();
// Send data to Parse.com for verification
ParseUser.logInInBackground(usernametxt, passwordtxt,
new LogInCallback() {
public void done(ParseUser user, ParseException e) {
if (user != null) {
// If user exist and authenticated, send user to Welcome.class
Intent intent = new Intent(
LoginSignupActivity.this,
Welcome.class);
startActivity(intent);
Toast.makeText(getApplicationContext(),
"Successfully Logged in",
Toast.LENGTH_LONG).show();
finish();
} else {
Toast.makeText(
getApplicationContext(),
"No such user exist, please signup",
Toast.LENGTH_LONG).show();
}
}
});
}
});
现在我需要获取当前用户的信息,请提及方法或更改我必须做的以获取当前用户的信息。
提前致谢!
答案 0 :(得分:2)
调用user.getObjectId();
或user.getString("username");
之类的内容是从ParseObject获取信息的方式。
loginbutton.setOnClickListener(new OnClickListener() {
public void onClick(View arg0) {
// Retrieve the text entered from the EditText
usernametxt = username.getText().toString();
passwordtxt = password.getText().toString();
// Send data to Parse.com for verification
ParseUser.logInInBackground(usernametxt, passwordtxt,
new LogInCallback() {
public void done(ParseUser user, ParseException e) {
if (user != null) {
// If user exist and authenticated, send user to Welcome.class
String username = user.getString("username");
String userId = user.getObjectId();
Intent intent = new Intent(
LoginSignupActivity.this,
Welcome.class);
startActivity(intent);
Toast.makeText(getApplicationContext(),
"Successfully Logged in",
Toast.LENGTH_LONG).show();
finish();
} else {
Toast.makeText(
getApplicationContext(),
"No such user exist, please signup",
Toast.LENGTH_LONG).show();
}
}
});
}
});
答案 1 :(得分:2)
用户通过身份验证后,打开新活动,然后使用静态方法getCurrentUser访问当前用户。
ParseUser currentUser = ParseUser.getCurrentUser();
if (currentUser != null) {
// do stuff with the user
} else {
// show the signup or login screen
}
答案 2 :(得分:1)
有了这个,我得到了用户信息。
ParseUser currentUser = ParseUser.getCurrentUser();
if (currentUser != null){
String email = currentUser.getEmail();
String username = currentUser.getUsername();
String objectID = currentUser.getObjectId();
} else {
Toast.makeText(getApplicationContext(), "the user does not exist!",Toast.LENGTH_SHORT).show();
}
答案 3 :(得分:0)
ParseUser currentUser = ParseUser.getCurrentUser();
currentUser.getUsername();
newTable.put("user_name",currentUser );
这是您在其他表(newTable)中获取用户信息的方法。 如果有帮助,请告诉我。 :)
答案 4 :(得分:0)
ParseUser currentUser = ParseUser.getCurrentUser();
String currentUserString = String.valueOf(currentUser.getUsername());
newTable.put("user_name",currentUserString);
由于某些原因我不确定,你需要将currentUser转换为String。