- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我在这个应用程序中有一个 Asynctask,我在 onPreExecute 中有一个 ProgressDialog。
ProgressDialog pDialog;
protected void onPreExecute() {
pDialog = new ProgressDialog(Synchronization.this);
pDialog.setMessage(Html.fromHtml("<b>Please Wait</b><br/>Working..."));
pDialog.setIndeterminate(false);
pDialog.setCancelable(false);
pDialog.show();
}
并且,在 onPostExecute 中,我关闭了这个对话框。
protected void onPostExecute(ArrayList<Object> allShopsData) {
// TODO Auto-generated method stub
super.onPostExecute(allShopsData);
final ArrayList<Object> allShops = allShopsData;
// dismiss the dialog after getting all products
if(pDialog!=null && pDialog.isShowing())
pDialog.dismiss();
// updating UI from Background Thread
runOnUiThread(new Runnable() {
public void run() {
ExpandableListView expandableList = (ExpandableListView) findViewById(R.id.expandlist);
expandableList.setDividerHeight(2);
expandableList.setGroupIndicator(null);
expandableList.setClickable(true);
MyExpandableAdapter adapter = new MyExpandableAdapter(taskList,
allShops);
adapter.setInflater(
(LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE),
Synchronization.ref);
expandableList.setAdapter(adapter);
}
});
}
我在同步(我的主要 Activity )onCreate() 中启动名为“task1”的 Asynctask。现在,我在 MainActivity 中有一个菜单,我在其中取消了“task1”引用的 Asynctask,并创建了另一个 Asynctask 实例,将其分配给“task1”。
task1.cancel(true);
task1 = new GetShopsTask();
task1.execute(taskList);
但在这里,我看到创建的一个进度对话框在 onPostExecute 之后关闭(我还可以看到我的 View 在后台更新)但紧接着,另一个进度对话框弹出,但没有被关闭。不确定,是什么部分造成的。有人可以帮忙吗?
最佳答案
问题是当您取消 AsyncTask 时,不会调用 onPostExecute 而是调用 onCanceled()。请参阅 AsyncTask 源代码。
private void finish(Result result) {
if (isCancelled()) {
onCancelled(result);
} else {
onPostExecute(result);
}
mStatus = Status.FINISHED;
}
因此您的进度对话框不会关闭,因为永远不会调用 onPostExecute。您可以通过将此添加到异步任务来解决问题:
@Override
protected void onCancelled()
{
// dismiss the dialog on canceled task
if(pDialog!=null && pDialog.isShowing())
pDialog.dismiss();
}
关于android - ProgressDialog 不会因多个 Asynctask 实例而关闭,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20556140/
当用户点击登录按钮时,我想在我的应用程序中使用 ProgressDialog。我遇到的问题是未找到 ProgressDialog - AS 中的红色文本。我错过了什么图书馆吗? 渐变 compile
我使用进度条创建了自定义进度对话框,但自定义进度对话框中的进度消息没有更新 最佳答案 您可以使用 ProgressBar实现相同的行为进度对话框 CustomProgressBar progressB
给出下面的代码。我想将标题“请等待调用被激活”转换为印地语(我在 Assets 文件夹中提供的字体).. public ShakeEventsListener(Context context, OnS
当我的设备是 4.4.4 时,我的 ProgressDialog 工作正常,我最近没有使用这个应用程序,同时设备升级到 Lillipop。我不确定这是否对这个问题造成了任何影响,只是提一下。 问题 1
ProgressDialog 在我的代码中添加 progressDialog.dismiss() 方法时无法显示 我还尝试添加Thread.sleep(),以便它的执行将 hibernate 一段时间
我只是想创建一个旋转的进度对话框。没有文字,没有边框,没有背景。只是一个旋转的通知,轻轻地位于内容顶部的屏幕中心。 我在创建这个自定义对话框时看到了两个不同的 Stack Overflow 问题。 他
我的意思是,ProgressDialog 静态方法 show() 的返回值与该类实例的非静态方法 show 之间有什么区别? 有什么理由选择这种策略 ProgressDialog pd = new P
我在进程运行时使用 ProgressDialog 时遇到问题。我已经尝试了所有可能的不正确方法,并查看了许多网站,这些网站提供了我正在尝试做的事情的示例,但是,我仍然遇到了线程在 ProgressDi
我开发了一个 Flutter 应用程序,我使用了 ProgressDialog小部件 ( progress_dialog: ^1.2.0 )。首先,我展示了 ProgressDialog小部件和一些代
在应用程序中创建ProgressDialog时,出现BadTokenException错误。我尝试阅读有关该问题的几篇文章,但我仍然无法真正弄清这是什么原因。单击按钮后,我调用对话框函数。 p
以下是我的代码: public void onClick(View view) { dialog=new ProgressDialog(view.getContext());
我有一个进度对话框,可以工作,但不符合我的外部需求: 我想把它做成这样: 我尝试过的: 1 - 主题化(仅使用样式和样式+主题方法),如此处所述 结果很糟糕(我在对话框周围有一个相同的蓝色边框颜色和标
我正在尝试从互联网获取数据,解析它,然后将数据显示给用户。该操作通常需要 3 秒左右,我希望旋转进度对话框显示一条消息,说明我正在加载数据。问题是 ProgressDialog 仅在加载即将完成时才显
我制作了一个食谱应用程序,我一直在解决一些问题,因为我无法运行该应用程序,但似乎每次修复错误时都会出现另一个错误,我的项目无法解决方法解雇()我不知道该怎么办,我已经根据 Youtube channe
我想从外部类中显示当前 Activity 的 ProgressDialog,而不是将变量传递到外部类或像其他已回答的问题一样使用静态变量。是否可以?这是一些简单的测试代码,可能有助于说明我想要做什么:
在“onCreate”中,我正在从网络下载数据。下载数据的持续时间为 10 秒。我不想在下载数据时使用 ProgressDialog。这是我的代码,但 ProgressDialog 没有出现: pub
我的应用程序正在从网络服务器加载一些数据。这次我想要一个进度对话框以避免应用程序用户出现黑屏。 Button ok = (Button) findViewById(R.id.ok);
我在我的 android 应用程序中创建了一个 ProgressDialog。但我遇到的问题是在它实际完成工作时停止旋转轮子。这是我的代码。我怎样才能让它在我进行其他工作时不断旋转轮子? button
我能做到: ((Activity) mContext).setProgressBarIndeterminateVisibility(true); 但不是这个: ((Activity) mConte
我想从服务内的线程增加一个进度对话框,我真的很难做到,这是我的代码,请帮助我。 我尝试了很多不同的方法,包括 asyncTask(我遇到了上下文问题)并尝试使用静态函数但它无法正常工作,我是 andr
我是一名优秀的程序员,十分优秀!