How do I create groups of ParseUsers using Parse.com?

android, grouping, parse-platform

Solution

I ended up doing as shown below:

 ParseQuery<ParseRole> query = ParseRole.getQuery();
 Intent intent = getActivity().getIntent();
 String groupId = intent.getStringExtra("groupId");
 query.whereEqualTo("objectId", groupId);
 groupUsers = new ArrayList<String>();
 query.findInBackground(new FindCallback<ParseRole>() {
     @Override
     public void done(List<ParseRole> objects, ParseException e) {
        if(e == null) {
            for(ParseRole role : objects) {
                ParseRelation<ParseUser> usersRelation = role.getRelation("users");
                ParseQuery<ParseUser> usersQuery = usersRelation.getQuery();
                usersQuery.findInBackground(new FindCallback<ParseUser>() {
                    @Override
                    public void done(List<ParseUser> objects, ParseException e) {
                        for(ParseUser user : objects) {
                            groupUsers.add(user.getUsername());
                        }
                    }           
                });
            }
         } else {
             Toast.makeText(getActivity(), "ERROR", Toast.LENGTH_SHORT).show();
         }              
      }                  
 });       

I passed in the group ID from the `Intent` that sent me to that `Fragment` that I was checking and then populated my `ListView` with the list that I've returned from the query on the Parse database with the specific group ID. I hope this helps anyone else who had the same issue as me. Good luck!

Problem

Currently I'm using Parse.com in order to create multiple ParseUsers. This works perfectly and each user can login individually. However from here I want to expand my app to allow Users to create groups of users and therefore have data that is only relevant and shared between these Users. This will mean that when the User logs in, they can see a List of the groups they are members of and from there can share data simply just to those users of that individual group. What would be the best way to tackle this and does anybody have any examples or tutorials that I could follow in order to understand this concept? I've considered creating a Group class and then making this store User's IDs in an array and then allow each User to store an array of the Group IDs that they're currently members of. I'm just not really sure how to broach this issue. Thanks in advance!

Original source