android 中进度对话框的问题
在我的应用程序中,当我单击按钮时,我将从网络获取一些数据,并且正在打开一个新活动。当时我试图在屏幕上显示进度条。以下是我的代码
dialog = new ProgressDialog(SearchPage.this);
dialog.setMessage("Please wait...");
dialog.setIndeterminate(true);
dialog.show();
new Thread() {
public void run() {
try {
Thread.sleep(300);
}
catch (InterruptedException e)
{
e.printStackTrace();
}
getWebPageContents(url);
Intent myIntent = new Intent(getBaseContext(), SearchList.class);
startActivityForResult(myIntent, 0);
}
}.start();
应用程序工作正常,进度对话框也正常工作。现在的问题是,当我按下第二个活动的后退按钮时,第一个活动将打开,进度对话框将启动并连续运行而不停止。
如果我按后退按钮,它就会停止。我不希望在返回第一个活动时查看进度对话框。如何做到这一点......
in my app when i click a button i am getting some data from network and i am opening a new activity. At that time i am trying to show a progress bar in my screen. Following is my code
dialog = new ProgressDialog(SearchPage.this);
dialog.setMessage("Please wait...");
dialog.setIndeterminate(true);
dialog.show();
new Thread() {
public void run() {
try {
Thread.sleep(300);
}
catch (InterruptedException e)
{
e.printStackTrace();
}
getWebPageContents(url);
Intent myIntent = new Intent(getBaseContext(), SearchList.class);
startActivityForResult(myIntent, 0);
}
}.start();
The app is working fine and the progress dialog is also working. Now the problem is when i press the back button from second activity the first activity gets opened and the progress dialog gets started and running continuously without stopping.
It gets stopped if i press the back button. I dont want the progress dialog to be viewed when i returning back to the first activity. How to do this........
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
在开始新活动之前调用
dialog.dismiss()
。希望这有帮助。Call
dialog.dismiss()
before starting the new activity. Hope this helps.之后添加以下代码
Add the following code after
您可以在调用 Activity 后直接关闭对话框,方法是调用
after
如果您只想在从此 Activity 返回时关闭对话框,则需要确保
dialog
是一个字段,并且在onActivityResult
中调用dialog.dismiss();
(您可能需要首先检查dialog != null
)。You can dismiss the dialog directly after your call to the Activity by calling
after
If you want to dismiss the dialog only when you've returned from this Activity, you need to make sure
dialog
is a field, and calldialog.dismiss();
inonActivityResult
(You may want to check fordialog != null
first).之后添加以下代码
Add following code after