Android/Java:没有调用 onProgressUpdate()?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/10706897/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-31 02:11:58  来源:igfitidea点击:

Android/Java: onProgressUpdate() not being called?

javaandroidbreakpoints

提问by qwerty

I've read similar threads on here, even googled but no solution.

我在这里读过类似的帖子,甚至用谷歌搜索过但没有解决方案。

onProgressUpdate() is just not being called.

onProgressUpdate() 只是没有被调用。

Here's the code:

这是代码:

public class DoHardWork extends AsyncTask {

    @Override
    protected Object doInBackground(Object... params) {


        publishProgress("Requesting XML data");
        this.requestData();

        publishProgress("Returning results");
        this.returnResults();

        return null;
    }



    protected void onProgressUpdate(String text) {
        super.onProgressUpdate(text);
        MainActivity.setLog(text);
    }
}

I tried setting a breakpoint in onProgressUpdate() and it's never called. It's like the code is just ignored.

我尝试在 onProgressUpdate() 中设置断点,但从未调用过。就像代码被忽略了一样。

Someone had a similar problem and it turned out to be just eclipse just messing with him but i tried restarting it with no success.

有人遇到了类似的问题,结果只是 eclipse 惹恼了他,但我尝试重新启动它但没有成功。

Any ideas?

有任何想法吗?

回答by Pablo

I think that you missed somethings on your code. Try with this one:

我认为您错过了代码中的某些内容。试试这个:

private class DoHardWork extends AsyncTask<Void, String, Long> {
    protected Long doInBackground(Void... urls) {
         publishProgress("Requesting XML data");
         this.requestData();

         publishProgress("Returning results");
         this.returnResults();

         return null;
    }

    protected void onProgressUpdate(String... progress) {
        super.onProgressUpdate(progress);
        MainActivity.setLog(progress[0]);
    }


}