AsyncTask ProgressDialog不与.get()一起显示

编程入门 行业动态 更新时间:2024-10-26 09:20:00
本文介绍了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()一起显示

本文发布于:2023-11-17 03:49:30,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1608720.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:不与   AsyncTask   ProgressDialog

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!