android - 解析 : make query finsih task before moving to the next task

标签 android parse-platform progress

这是主要的。 按钮-

                    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/

相关文章:

parse-platform - 在云代码中保存或更新 ParseUser

ios - Swift Parse - 将对象保存在关键位置

jquery - 如何知道 $(window).load();来自 jquery 的状态

java - 如何在 Android ProgressDialog 中显示 SecondaryProgress?

android - 如何以编程方式更改壁纸?

Android - ListView 项目更改项目的高度

android - 扩展 MultiDexApplication 和 MultiDex.install(this) 有什么区别?

android - 验证 Paypal 自适应支付

ios - Swift 解析查询结果未出现在 TableView 中

html - 完全加载后播放html5视频