this is the main. the buttons-
public void onClick(View v) {
dialog.show();
getTheMarkerId();
markerisfalseortrue(0);
dialog.hide();
cdd.dismiss();
}
});
this is the first task: getTheMarkerId()
queryfindmarkerid.findInBackground(new FindCallback<ParseObject>() {
@Override
public void done(List<ParseObject> parseObjects, ParseException e) {
for (int i = 0; i<parseObjects.size(); i++)
{
if (parseObjects.get(i).getInt("longit") == themarkerlongitude && parseObjects.get(i).getInt("latit") == themarkerlatitude)
{
themarkerid = parseObjects.get(i).getObjectId();
}
}
}
});
this is the second task- markerisfalseortrue(int i)
if (i == 0)
{
queryfindmarkerid.getInBackground( themarkerid, new GetCallback<ParseObject>() {
public void done(ParseObject gameScore, ParseException e) {
if (e == null) {
nowscore = gameScore.getInt("false");
gameScore.put("false", nowscore +1 );
gameScore.saveInBackground();
}
}
});
The problem is: This query has an outstanding network connection. You have to wait until it's done. How could I wait until the firse task is completed.
Put the method call markerisfalseortrue(0);
inside of the done method of the getTheMarkerId() method. That way, the markerisfalseortrue() method won't run until the first network call has completed.
That is a common pattern to remember using the Parse querying methods with their callbacks - if you need to make a second request, or perform some action that can only be completed after the first network call has completed, activate that action in the done method of the first network call.