1

I'm meeting a problem in my current app, the app containt following/follower system, when I look to user profil I want to retrieve an information if I'm already following this user or not. this is my code

private class CheckinIfFollowing extends AsyncTask<Void, Void, Void> {
                @Override
                protected void onPreExecute() {
                    super.onPreExecute();
                     //preexcution
                }

                @Override
                protected Void doInBackground(Void... params) {
                    ParseQuery<ParseObject> query = ParseQuery.getQuery("Follow");
                    query.whereEqualTo("from", ParseUser.getCurrentUser());
                    query.whereEqualTo("to", userId);
                    query.getFirstInBackground(new GetCallback<ParseObject>() {
                        @Override
                        public void done(ParseObject object, ParseException e) {
                            if(e==null){
                                Toast.makeText(UserProfil.this, "blue", Toast.LENGTH_SHORT).show();
                                //btn_follow.setButtonColor(getResources().getColor(R.color.bleu));
                            }else{
                            if(e.getCode() == ParseException.OBJECT_NOT_FOUND)
                                  {
                                Toast.makeText(UserProfil.this, "pink", Toast.LENGTH_SHORT).show();
                                //btn_follow.setButtonColor(getResources().getColor(R.color.pink));  
                                  }
                                  else
                                  {
                                  //unknown error, debug
                                  }
                                 }


                        }
                    });

            return null;
                }

                @Override
                protected void onPostExecute(Void result) {
                //  followingButton(AlreadyFollowing);
                //  btn_follow.setClickable(true);
                }
                }

I'm executing the AsyncTask but nothing shown in the screen.

Btw the "from" and "to" column of the Follow class in parse.com are pointers to _User.

1
  • isn't ParseQuery already Asynchronous? Commented Dec 8, 2015 at 22:04

1 Answer 1

1

First of all (that's not directly related to your issue, just an observatino): if you're using <something>InBackground method of a query, you don't have to put it inside an AsyncTask. It's already being executed in the background. In your case, you are basically (simplifying a bit here) executing an async task from an async task.


Although you didn't say what's stored in the userId object, I'm assuming (based on it's name) it's an objectId of a ParseUser object and not a ParseUser object itself. And I believe that's a reason for your issue. This line to be exact:

query.whereEqualTo("to", userId);

You said:

Btw the "from" and "to" column of the Follow class in parse.com are pointers to _User.

If you're storing Pointer to another ParseObject you should probably be passing this type of an object if you're using this field in a query (and not an objectId - String). So in your case you should be passing an instance of ParseUser instead of its objectId.

You can use createWithoutData method of ParseObject to create an object (with objectId) that you can use for your query.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.