android 中进度对话框的问题

发布于 2024-11-18 00:20:56 字数 764 浏览 3 评论 0原文

在我的应用程序中,当我单击按钮时,我将从网络获取一些数据,并且正在打开一个新活动。当时我试图在屏幕上显示进度条。以下是我的代码

 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

千柳 2024-11-25 00:20:56

在开始新活动之前调用 dialog.dismiss()。希望这有帮助。

Call dialog.dismiss() before starting the new activity. Hope this helps.

铁轨上的流浪者 2024-11-25 00:20:56

之后添加以下代码

startActivityForResult(myIntent, 0);
dialog.dismiss();

Add the following code after

startActivityForResult(myIntent, 0);
dialog.dismiss();
简单气质女生网名 2024-11-25 00:20:56

您可以在调用 Activity 后直接关闭对话框,方法是调用

dialog.dismiss();

after

startActivityForResult(myIntent, 0);

如果您只想在从此 Activity 返回时关闭对话框,则需要确保 dialog 是一个字段,并且在 onActivityResult 中调用 dialog.dismiss();(您可能需要首先检查 dialog != null)。

You can dismiss the dialog directly after your call to the Activity by calling

dialog.dismiss();

after

startActivityForResult(myIntent, 0);

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 call dialog.dismiss(); in onActivityResult(You may want to check for dialog != null first).

三生一梦 2024-11-25 00:20:56

之后添加以下代码

dialog.setMessage("Please wait...");
dialog.setCancelable(false);

Add following code after

dialog.setMessage("Please wait...");
dialog.setCancelable(false);
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文