使用Parse获取其他查询列

时间:2015-10-15 20:05:32

标签: java android parse-platform

我正在尝试使用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();
                    }
                }
            });

2 个答案:

答案 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");

或者您可以使用它:https://guides.codepath.com/android/Building-Data-driven-Apps-with-Parse#passing-objects-between-activities

答案 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
    }