首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >onProgressUpdate未运行

onProgressUpdate未运行
EN

Stack Overflow用户
提问于 2018-04-10 21:42:47
回答 2查看 69关注 0票数 0

我正在使用Retrofit从api接收json数据,并且工作得很好,但将来我想显示一个进度条。我决定实现onProgressUpdate,以检查是否调用了此方法,但当检查Logcat选项卡时,它不起作用。也就是说,该方法没有运行。AsyncTask类中的所有其他方法都可以正常工作。我为每个方法都有一个Toast,所有这些方法都会运行。

代码语言:javascript
复制
public class MindicadorTask extends AsyncTask<Void, Void, Void> {

        private String TAG = MindicadorTask.class.getSimpleName();

        @Override
        protected void onPreExecute() {
            super.onPreExecute();
            Toast.makeText(MainActivity.this, "JSON Downloading", Toast.LENGTH_SHORT).show();
        }

        @Override
        protected Void doInBackground(Void... voids) {

            Retrofit retrofit = new Retrofit.Builder()
                    .baseUrl(IMindicador.BASE_URL)
                    .addConverterFactory(GsonConverterFactory.create())
                    .build();
            IMindicador iMindicador = retrofit.create(IMindicador.class);

            Call<Mindicador> call = iMindicador.getAPI();

            mMindicador = new Mindicador();
            try {
                mMindicador = call.execute().body();
            } catch (IOException e) {
                Log.e(TAG, "" + e.getMessage());
            }

            return null;
        }

        @Override
        protected void onProgressUpdate(Void... values) {
            super.onProgressUpdate(values);
            Log.e(TAG, "onProgressUpdate was called");
        }

        @Override
        protected void onPostExecute(Void aVoid) {
            super.onPostExecute(aVoid);
            Toast.makeText(MainActivity.this, "JSON Call was sucessfull", Toast.LENGTH_SHORT).show();
        }
    }
EN

Stack Overflow用户

发布于 2018-04-10 21:48:18

你必须给它传递一些值,而不是Void。例如,尝试使用int。当int迭代时,它调用onProgressUpdate()。

票数 2
EN
查看全部 2 条回答
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/49755255

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档