Chipset
Chipset

Reputation: 51

Parse Android get Users List

I have this function in my App for making a leaderboard. When executing, it never goes reaches the for loop and I'm unable to update my leaderboard. Is there any better implementation for the same?

public void updateLeaderboard(final Context context) {
        Log.d("Leaderboard ", "Updating");
        ParseQuery<ParseObject> query = ParseQuery.getQuery(KEY_USER_CLASS);
        query.addDescendingOrder(KEY_LAST_LEVEL);
        query.addAscendingOrder(KEY_CROSSED_AT);
        query.whereNotEqualTo(KEY_ADMIN, true);
        query.whereEqualTo(KEY_EMAIL_VERFIFIED, true);
        query.findInBackground(new FindCallback<ParseObject>() {

            @Override
            public void done(List<ParseObject> users, ParseException e) {
                Log.d("Leaderboard ", "done() caled");
                if (e == null) {
                    Log.d("Leaderboard ", "inside if");

                    for (int i = 0; i < users.size(); i++) {
                        ParseObject user = users.get(i);
                        Log.d("Leaderboard ",
                                "Updating user " + String.valueOf(i + 1));
                        user.put(KEY_RANK, i + 1);
                        user.saveInBackground(new SaveCallback() {

                            @Override
                            public void done(ParseException e) {
                                if (e == null) {
                                    Log.d("Leader", "Saved");
                                } else {
                                    Toast.makeText(context, e.getMessage(),
                                            Toast.LENGTH_SHORT).show();
                                }

                            }
                        });
                    }

                } else {
                    Toast.makeText(context, e.getMessage(), Toast.LENGTH_SHORT)
                            .show();
                }
            }
        });

        Log.d("Leaderboard ", "Closing");
    }

Upvotes: 1

Views: 3722

Answers (1)

Timothy Walters
Timothy Walters

Reputation: 16884

Most common cause is not realising that the "User", "Role" and "Installation" classes are special, their actual names are "_User", "_Role" and "_Installation", though to do a query on the User class the recommended method is:

ParseQuery<ParseUser> query = ParseUser.getQuery();

Upvotes: 9

Related Questions