Android - 进度对话框未关闭
我有一个 ListActivity 类,当单击列表中的任何项目时,都会显示一个新活动。新活动需要时间来加载,所以我希望用户知道正在发生一些事情(以进度对话框的形式)
因此,为了做到这一点,我在我的类中实现了 Runnable,如下所示 -
public class ProtocolListActivity extends ListActivity implements Runnable {
private ProgressDialog progDialog;
....
protected void onListItemClick(ListView l, View v, int position, long id) {
progDialog.show(this, "Showing Data..", "please wait", true, false);
Thread thread = new Thread(this);
thread.start();
}
....
public void run() {
// some code to start new activity based on which item the user has clicked.
}
最初,当我单击,正在加载新活动,进度对话框运行良好,但是当我关闭上一个活动(返回到此列表)时,进度对话框仍在运行。我希望进度对话框仅在新活动开始时显示。
有人可以指导我如何正确执行此操作吗?
I have a ListActivity class, and when any item on the list is clicked, a new activity is displayed. The new activity takes time to load, so i would like the users to know that there is something happening (in the form of a progress dialog)
So, in order to do this, i implemented Runnable in my class like this -
public class ProtocolListActivity extends ListActivity implements Runnable {
private ProgressDialog progDialog;
....
protected void onListItemClick(ListView l, View v, int position, long id) {
progDialog.show(this, "Showing Data..", "please wait", true, false);
Thread thread = new Thread(this);
thread.start();
}
....
public void run() {
// some code to start new activity based on which item the user has clicked.
}
Initially, when i click, and the new activity is being loaded, the progress dialog works nicely, but when i close the previous activity (to get back to this list) the progress dialog is still running. I want the progress dialog to show up only for the time the new activity is being started.
Can someone please guide me on how to do this correctly.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
对话框需要由程序员显式删除(或由用户关闭)。因此,应该这样完成:
在 Activity A(调用 Activity)中
虽然在大多数用例中,繁重的工作应该在被调用者 Activity 上。万一,繁重的工作是由被调用者的
onCreate
完成的,它应该是这样的:Activity B (Callee):
无论如何,想法仍然是一样的。
Dialogs needs to be explicitly removed by programmer (or close by user). So, it should be done in this way:
in Activity A (calling activity)
Although in most use case, the heavy work should be on the callee Activity. In case, the heavy work is done
onCreate
of the callee, it should be like:Activity B (Callee):
Anyway, the idea is still the same.