0

I have to fetch some data from the parse cloud. I'm using the parse sdk for android. How do I call the method findInBackground asynchronously in my activity? Essentially, where do I place this piece of code in my Activity? Below is my code:

ParseQuery<ParseObject> query = ParseQuery.getQuery("Average");
    query.whereEqualTo("squarefeet", area);
    query.findInBackground(new FindCallback<ParseObject>() {

        public void done(List<ParseObject> objects, ParseException e) {
            if (e == null) {
                if (objects.size() > 0) {

                    for (int i = 0; i < objects.size(); i++) {
                        ParseObject p = objects.get(i);
                        averageConsumption = p
                                .getNumber("average_consumption");
                        efficientConsumption = p
                                .getNumber("efficient_consumption");
                    }
                }

            } else {
                // something went wrong!
            }
        }

    });
  • you want to call this method in using async ?? that's the question right?? – srikanth Jun 06 '15 at 10:30
  • yes... I want to call it asynchronously.. – Aditya Prabhu Jun 06 '15 at 10:33
  • if that is what you wish to do create a async task refer here[http://developer.android.com/reference/android/os/AsyncTask.html – srikanth Jun 06 '15 at 10:34
  • findInBackground itself is an asynchronous call. My exact question is how do I use it in my Activity? – Aditya Prabhu Jun 06 '15 at 10:38
  • for a async task in android all that we do is create a new instance and call its instance.execute() method.... but in parse sdk there should be something similar... isn't the docs saying anything about this??? – srikanth Jun 06 '15 at 10:44
  • 1
    were do u wish to obtain the data from cloud if it is on starting of app ...thn in onCreate/onStart methods.. if it is on click of a button etc.. in onclick method event try to call this code.. – srikanth Jun 06 '15 at 11:09

1 Answers1

0

I called it inside an OnClick method of an OnClickListener. This made it asynchronous! Pretty silly but works! Previously I called it synchronously in OnCreate.