I am quite new to Java/android programming and I'm stuck at the Parse.com callback.
In have a method (method1) that requests the objectId of an object owned by the current user. It does this by calling upon another method (method2) that contains a query which pulls an object from the data browser with a callback.
I managed to write all code but I'm stuck at the callback for method 2. I want the object data to be returned to method 1 but this seems to be inpossible because of the Callback type (void).
I also do now know how to let the rest of the method wait for the callback to return before executing.. I would appreciate it if anyone could help me out.
This is my code:
public void method1(){
String objectId = null;
objectId = QueryStatisticObjectId("Age");
Log.i(TAG, "objectId returned to method = " + objectId);
}
public String QueryStatisticObjectId(final String statistic){
ParseQuery<ParseObject> query = ParseQuery.getQuery("Statistics");
query.whereEqualTo("user", ParseUser.getCurrentUser());
query.whereEqualTo("statistic", statistic);
query.getFirstInBackground(new GetCallback<ParseObject>() {
@Override
public void done(ParseObject object, ParseException e) {
if (e == null){
//We have data!
String objectId = object.getObjectId();
return;
}
else
{
//Something went wrong!?!
e.printStackTrace();
}
}
});