这是主要的。 按钮-
public void onClick(View v) {
dialog.show();
getTheMarkerId();
markerisfalseortrue(0);
dialog.hide();
cdd.dismiss();
}
});
这是第一个任务: 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();
}
}
}
});
这是第二个任务- 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();
}
}
});
问题是: 此查询具有未完成的网络连接。你必须等到它完成。 怎么等到第一个任务完成。
最佳答案
将方法调用 markerisfalseortrue(0);
放在 getTheMarkerId() 方法的 done 方法中。这样,markerisfalseortrue() 方法将不会运行,直到第一个网络调用完成。
这是一个常见的模式,要记住使用带有回调的 Parse 查询方法 - 如果您需要发出第二个请求,或者执行某些只能在第一个网络调用完成后才能完成的操作,请在第一次网络调用的 done 方法。
关于android - 解析 : make query finsih task before moving to the next task,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25463574/