我有_Role表,有三个角色" Role1"," Role2"," Role" 每个角色都有相关用户Relation< _User>
我以用户身份登录
ParseUser.logInInBackground(login, password, new LogInCallback() {
public void done(ParseUser user, ParseException e) {
if (user != null) {
Log.d("Parse", "User logged in successfully");
SharedPreferencesController.getInstance(getApplicationContext()).signInUser(login);
Intent intent=new Intent(LoginActivity.this,ViewPagerActivity.class);
startActivity(intent);
finish();
return;
} else {
Log.d("Parse", "Failed to login");
Toast.makeText(getApplicationContext(),"Failed to login",Toast.LENGTH_SHORT).show();
}
然后我想找出我的用户的角色,我该怎么做?
我试过
ParseUser currentUser = ParseUser.getCurrentUser();
if (currentUser != null) {
} else {
// show the signup or login screen
}
ParseQuery<ParseObject> query = ParseQuery.getQuery("_Role");
query.whereEqualTo("users", currentUser);
query.findInBackground(new FindCallback<ParseObject>() {
@Override
public void done(List<ParseObject> categoryAttributes, ParseException e) {
if (e == null) {
for (ParseObject ob : categoryAttributes) {
Log.e("DATA", "ObjectID: " + ob.getObjectId());
// Log.e("DATA", "Column1: " + ob.getString("name"));
}
} else {
Log.v("DATA", "Error: " + e.getMessage());
// Alert.alertOneBtn(getActivity(),"Something went wrong!");
}
}
});
但categoryAttributes为空
我搞定了
if (currentUser != null) {
ParseQuery<ParseObject> query = ParseQuery.getQuery("_Role");
query.whereEqualTo("users", currentUser);
query.findInBackground(new FindCallback<ParseObject>() {
public void done(List<ParseObject> commentList, ParseException e) {
// commentList now has the comments for myPost
if (e == null) {
for (ParseObject ob : commentList) {
Log.e("DATA", "ObjectID: " + ob.getObjectId());
Log.e("DATA", "Column1: " + ob.getString("name"));
listener.findRole(ob.getString("name"));
}
}
}
});