简体   繁体   中英

Removing a relation from a ParseUser in Parse.com android

I am trying to remove a realtion from a ParseUser in Parse.com. I tried to find in the internet how to do this but I came with no success. Someone here can help me? or give ma clue? It just can't seem to wotk for me.

I tried the following code:

@Override
public void onDismiss(final AbsListView listView,
        final int[] reverseSortedPositions) {

    for (int position : reverseSortedPositions) {

        ParseQuery<ParseUser> query = ParseUser.getQuery();
        query.whereEqualTo("username", values.get(position));
        query.findInBackground(new FindCallback<ParseUser>() {
            public void done(List<ParseUser> objects, ParseException e) {

                if (objects.size() != 0) {
                    if (objects.get(0).getUsername() != null) {



                        final ParseUser currentUser = ParseUser
                                .getCurrentUser();
                        if (currentUser != null) {
                            {

                                final ParseObject friend = new ParseObject(
                                        "Friends");
                                friend.remove(values.get(position));

                                friend.deleteInBackground(new DeleteCallback() {

                                    @Override
                                    public void done(ParseException e) {
                                        ParseRelation relation = currentUser
                                                .getRelation("Friends");
                                        relation.remove(friend);
                                        Toast.makeText(getApplicationContext(),
                                        "Player Has Been
                                        Remove"+values.get(position),
                                        Toast.LENGTH_SHORT).show();

                                        currentUser.saveInBackground();
                                    }
                                });
                });

                                Toast.makeText(getApplicationContext(),
                                        "Player Has Been Added",
                                        Toast.LENGTH_SHORT).show();

                            }
                        }

                        //dialog.hide();
                    }

                } 
            }
        });

        adapt.remove(values.get(position));
        adapt.notifyDataSetChanged();

    }


}

please, I need your help. and sorry for my poor english

Try modifying your code to this, my guess is setting the template to ParseObject is important for linking the relation to the user.

ParseRelation<ParseObject> relation = currentUser.getRelation("Friends");
relation.remove(friend);
Toast.makeText(getApplicationContext(), "Player Has Been Add2321434243ed",Toast.LENGTH_SHORT).show();
currentUser.saveInBackground();

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM