AsyncTask ProgressDialog不与.get()一起显示 [英] AsyncTask ProgressDialog not showing with .get()

查看:83
本文介绍了AsyncTask ProgressDialog不与.get()一起显示的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用AsyncTask子类进行某些后台处理.问题是,当我将类与.get()方法一起使用时,在onPreExecute()中指定的ProgressDialog不会显示.

I'm using an AsyncTask subclass for some background processing. The problem is that when I use the class with the .get() method, the ProgressDialog I specify in the onPreExecute() does not show.

如果我在onPostExecute()方法中使用回调,则可以正常工作.

I works fine if I use a callback withing the onPostExecute() method.

我的第一个想法是,这是因为.get()等待该过程完成,但是也不能阻塞UI线程,所以不是这种情况.

My first thought was that this was because the .get() waits for the process to complete but that can't be blocking the UI thread either so that's not the case.

任何人都可以解释这种现象的原因以及是否有解决方法吗?如果可以的话,我真的很想使用.get()方法.

Can anyone explain why this behavior is so and if there is a workaround for this ?? I'd really like to use the .get() method if I can.

推荐答案

我最初接受了其他答案,但这似乎是错误的.

I initially accepted the other answer but it seems to be wrong.

.get()方法将阻止UI线程等待结果,并且显示的所有对话框也将被阻止.这是此方法的预期行为.

The .get() method will block the UI thread to wait for the result and any dialogs displayed will also be blocked. This is the expected behavior for this method.

唯一的选择是,如果后台活动持续了很长时间,则不使用.get(),而是对调用活动使用回调方法.

The only alternative is to not use .get() if the background activity is for any noticable amount of time and instead use callback methods to the calling activity.

这篇关于AsyncTask ProgressDialog不与.get()一起显示的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆