我正在尝试使用Parse SDK在我的Android应用程序中实现注册/登录系统。
到目前为止,我已经制作了寄存器&可以登录。
我正在寻找的是在其他活动上显示其他用户凭据(例如first_name或last_name)。
这是我的代码:
LoginActivity.java
//Read user information as String.
String email = etEmail.getText().toString();
String password = etPassword.getText().toString();
//Find user by Email and Password.
ParseQuery<ParseObject> query = ParseQuery.getQuery("Users");
query.whereEqualTo("email", email);
query.whereEqualTo("password", password);
query.findInBackground(new FindCallback<ParseObject>() {
public void done(List<ParseObject> users, ParseException e) {
if (e == null) {
//User logged in successful.
Toast.makeText(LoginActivity.this, "Welcome back!", Toast.LENGTH_SHORT).show();
//Take user to FeedActivity.
startActivity(new Intent(LoginActivity.this, FeedActivity.class));
} else {
//User login failed.
Toast.makeText(LoginActivity.this, "Login failed.", Toast.LENGTH_SHORT).show();
e.printStackTrace();
}
}
});
RegisterActivity.java
//Store user information in String.
String firstname = etFirstname.getText().toString();
String lastname = etLastname.getText().toString();
String email = etEmail.getText().toString();
String password = etPassword.getText().toString();
int userID = count.getAndIncrement();
ParseObject Users = new ParseObject("Users");
Users.put("userID", userID);
Users.put("first_name", firstname);
Users.put("last_name", lastname);
Users.put("email", email);
Users.put("password", password);
Users.saveInBackground(new SaveCallback() {
@Override
public void done(ParseException e) {
if (e == null) {
//User registered successfully.
Toast.makeText(RegisterActivity.this, "Registration successful."
, Toast.LENGTH_SHORT).show();
//Take user to LoginActivity.
startActivity(new Intent(RegisterActivity.this, LoginActivity.class));
} else {
Toast.makeText(RegisterActivity.this, "Registration failed."
, Toast.LENGTH_SHORT).show();
e.printStackTrace();
}
}
});
答案 0 :(得分:0)
您可能想检查通过Intent
发送数据。
所以在第一个活动中你这样做:
Intent i = new Intent(FirstActivity.this, SecondActivity.class);
i.putExtra("label", "My name, yo!");
startActivity(i);
和第二项活动:
Intent d = getIntent();
String s = d.getStringExtra("label");
答案 1 :(得分:0)
如果我找到了你想要的东西:
if (ParseUser.getCurrentUser() != null) {
String user = ParseUser.getCurrentUser().getObjectId();
ParseQuery<ParseObject> query = ParseQuery.getQuery("User");
query.whereEqualTo("objectId",user);
query.findInBackground(new FindCallback<ParseObject>() {
public void done(List<ParseObject> objects, ParseException e) {
if (e == null) {
for (final ParseObject post : objects) {
// Put Data in TextBoxes
// String first_name = post.getString("first_name"); - Will return first Name
}
}
}
});
} else {
//Log in the User
}