使用处理程序结束进度对话框

发布于 2024-11-29 01:22:20 字数 4372 浏览 2 评论 0原文

我需要知道如何在 http post 完成后关闭进度对话框。

这是我到目前为止所拥有的:

httppost.setEntity(me);

 HttpResponse responsePOST = client.execute(httppost);  
 HttpEntity resEntity = responsePOST.getEntity(); 

 InputStream inputstream = resEntity.getContent();
 BufferedReader buffered = new BufferedReader(new InputStreamReader(inputstream));
 StringBuilder stringbuilder = new StringBuilder();
 String currentline = null; 

 while ((currentline = buffered.readLine()) != null)
    { 
     stringbuilder.append(currentline + "\n"); 
     String result = stringbuilder.toString(); 
     Log.v("HTTP UPLOAD REQUEST",result); 
     inputstream.close();  
     handler.sendMessage(handler.obtainMessage());}
      }
     catch (Exception e) {
     e.printStackTrace();
     Toast.makeText(share.this, "Upload failed", Toast.LENGTH_SHORT).show();
    }
    }

    });

    background.start();
    }

    Handler handler = new Handler (){
    public void HandleMessage (Message msg){
    dialog.dismiss();
    }
    };

它不起作用,我应该在发送消息处理程序中放入什么来告诉处理程序关闭?提前感谢

Janail 在您更正后给了我这些错误:

08-15 10:08:20.020: ERROR/AndroidRuntime(25690): FATAL EXCEPTION: Thread-10
08-15 10:08:20.020: ERROR/AndroidRuntime(25690): java.lang.RuntimeException: Can't create handler inside thread that has not called Looper.prepare()
08-15 10:08:20.020: ERROR/AndroidRuntime(25690):     at android.os.Handler.<init>(Handler.java:121)
08-15 10:08:20.020: ERROR/AndroidRuntime(25690):     at android.widget.Toast.<init>(Toast.java:68)
08-15 10:08:20.020: ERROR/AndroidRuntime(25690):     at android.widget.Toast.makeText(Toast.java:231)
08-15 10:08:20.020: ERROR/AndroidRuntime(25690):     at com.apapa.vrsixty.share$2$2.run(share.java:130)
08-15 10:08:20.020: ERROR/AndroidRuntime(25690):     at java.lang.Thread.run(Thread.java:1027)
08-15 10:08:20.781: ERROR/WindowManager(25690): Activity com.apapa.vrsixty.share has leaked window com.android.internal.policy.impl.PhoneWindow$DecorView@4054d2f8 that was originally added here
08-15 10:08:20.781: ERROR/WindowManager(25690): android.view.WindowLeaked: Activity com.apapa.vrsixty.share has leaked window com.android.internal.policy.impl.PhoneWindow$DecorView@4054d2f8 that was originally added here
08-15 10:08:20.781: ERROR/WindowManager(25690):     at android.view.ViewRoot.<init>(ViewRoot.java:277)
08-15 10:08:20.781: ERROR/WindowManager(25690):     at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:148)
08-15 10:08:20.781: ERROR/WindowManager(25690):     at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:91)
08-15 10:08:20.781: ERROR/WindowManager(25690):     at android.view.Window$LocalWindowManager.addView(Window.java:433)
08-15 10:08:20.781: ERROR/WindowManager(25690):     at android.app.Dialog.show(Dialog.java:265)
08-15 10:08:20.781: ERROR/WindowManager(25690):     at android.app.ProgressDialog.show(ProgressDialog.java:107)
08-15 10:08:20.781: ERROR/WindowManager(25690):     at android.app.ProgressDialog.show(ProgressDialog.java:90)
08-15 10:08:20.781: ERROR/WindowManager(25690):     at com.apapa.vrsixty.share$2.onClick(share.java:91)
08-15 10:08:20.781: ERROR/WindowManager(25690):     at android.view.View.performClick(View.java:2532)
08-15 10:08:20.781: ERROR/WindowManager(25690):     at android.view.View$PerformClick.run(View.java:9293)
08-15 10:08:20.781: ERROR/WindowManager(25690):     at android.os.Handler.handleCallback(Handler.java:587)
08-15 10:08:20.781: ERROR/WindowManager(25690):     at android.os.Handler.dispatchMessage(Handler.java:92)
08-15 10:08:20.781: ERROR/WindowManager(25690):     at android.os.Looper.loop(Looper.java:143)
08-15 10:08:20.781: ERROR/WindowManager(25690):     at android.app.ActivityThread.main(ActivityThread.java:4263)
08-15 10:08:20.781: ERROR/WindowManager(25690):     at java.lang.reflect.Method.invokeNative(Native Method)
08-15 10:08:20.781: ERROR/WindowManager(25690):     at java.lang.reflect.Method.invoke(Method.java:507)
08-15 10:08:20.781: ERROR/WindowManager(25690):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
08-15 10:08:20.781: ERROR/WindowManager(25690):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
08-15 10:08:20.781: ERROR/WindowManager(25690):     at dalvik.system.NativeStart.main(Native Method)

I need to know how to dismiss my progress dialogue when a http post is done.

This is what I have so far:

httppost.setEntity(me);

 HttpResponse responsePOST = client.execute(httppost);  
 HttpEntity resEntity = responsePOST.getEntity(); 

 InputStream inputstream = resEntity.getContent();
 BufferedReader buffered = new BufferedReader(new InputStreamReader(inputstream));
 StringBuilder stringbuilder = new StringBuilder();
 String currentline = null; 

 while ((currentline = buffered.readLine()) != null)
    { 
     stringbuilder.append(currentline + "\n"); 
     String result = stringbuilder.toString(); 
     Log.v("HTTP UPLOAD REQUEST",result); 
     inputstream.close();  
     handler.sendMessage(handler.obtainMessage());}
      }
     catch (Exception e) {
     e.printStackTrace();
     Toast.makeText(share.this, "Upload failed", Toast.LENGTH_SHORT).show();
    }
    }

    });

    background.start();
    }

    Handler handler = new Handler (){
    public void HandleMessage (Message msg){
    dialog.dismiss();
    }
    };

It doesnt work, what am I suppose to put in the send message handler to tell the handler to dismiss?? Thanks in advance

Janail after you correction it gives me these errors:

08-15 10:08:20.020: ERROR/AndroidRuntime(25690): FATAL EXCEPTION: Thread-10
08-15 10:08:20.020: ERROR/AndroidRuntime(25690): java.lang.RuntimeException: Can't create handler inside thread that has not called Looper.prepare()
08-15 10:08:20.020: ERROR/AndroidRuntime(25690):     at android.os.Handler.<init>(Handler.java:121)
08-15 10:08:20.020: ERROR/AndroidRuntime(25690):     at android.widget.Toast.<init>(Toast.java:68)
08-15 10:08:20.020: ERROR/AndroidRuntime(25690):     at android.widget.Toast.makeText(Toast.java:231)
08-15 10:08:20.020: ERROR/AndroidRuntime(25690):     at com.apapa.vrsixty.share$2$2.run(share.java:130)
08-15 10:08:20.020: ERROR/AndroidRuntime(25690):     at java.lang.Thread.run(Thread.java:1027)
08-15 10:08:20.781: ERROR/WindowManager(25690): Activity com.apapa.vrsixty.share has leaked window com.android.internal.policy.impl.PhoneWindow$DecorView@4054d2f8 that was originally added here
08-15 10:08:20.781: ERROR/WindowManager(25690): android.view.WindowLeaked: Activity com.apapa.vrsixty.share has leaked window com.android.internal.policy.impl.PhoneWindow$DecorView@4054d2f8 that was originally added here
08-15 10:08:20.781: ERROR/WindowManager(25690):     at android.view.ViewRoot.<init>(ViewRoot.java:277)
08-15 10:08:20.781: ERROR/WindowManager(25690):     at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:148)
08-15 10:08:20.781: ERROR/WindowManager(25690):     at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:91)
08-15 10:08:20.781: ERROR/WindowManager(25690):     at android.view.Window$LocalWindowManager.addView(Window.java:433)
08-15 10:08:20.781: ERROR/WindowManager(25690):     at android.app.Dialog.show(Dialog.java:265)
08-15 10:08:20.781: ERROR/WindowManager(25690):     at android.app.ProgressDialog.show(ProgressDialog.java:107)
08-15 10:08:20.781: ERROR/WindowManager(25690):     at android.app.ProgressDialog.show(ProgressDialog.java:90)
08-15 10:08:20.781: ERROR/WindowManager(25690):     at com.apapa.vrsixty.share$2.onClick(share.java:91)
08-15 10:08:20.781: ERROR/WindowManager(25690):     at android.view.View.performClick(View.java:2532)
08-15 10:08:20.781: ERROR/WindowManager(25690):     at android.view.View$PerformClick.run(View.java:9293)
08-15 10:08:20.781: ERROR/WindowManager(25690):     at android.os.Handler.handleCallback(Handler.java:587)
08-15 10:08:20.781: ERROR/WindowManager(25690):     at android.os.Handler.dispatchMessage(Handler.java:92)
08-15 10:08:20.781: ERROR/WindowManager(25690):     at android.os.Looper.loop(Looper.java:143)
08-15 10:08:20.781: ERROR/WindowManager(25690):     at android.app.ActivityThread.main(ActivityThread.java:4263)
08-15 10:08:20.781: ERROR/WindowManager(25690):     at java.lang.reflect.Method.invokeNative(Native Method)
08-15 10:08:20.781: ERROR/WindowManager(25690):     at java.lang.reflect.Method.invoke(Method.java:507)
08-15 10:08:20.781: ERROR/WindowManager(25690):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
08-15 10:08:20.781: ERROR/WindowManager(25690):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
08-15 10:08:20.781: ERROR/WindowManager(25690):     at dalvik.system.NativeStart.main(Native Method)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(1

遥远的绿洲 2024-12-06 01:22:20

尝试这样

HttpResponse responsePOST = client.execute(httppost);  
 HttpEntity resEntity = responsePOST.getEntity(); 

 InputStream inputstream = resEntity.getContent();
 BufferedReader buffered = new BufferedReader(new InputStreamReader(inputstream));
 StringBuilder stringbuilder = new StringBuilder();
 String currentline = null; 

 while ((currentline = buffered.readLine()) != null)
    { 
     stringbuilder.append(currentline + "\n"); 
     String result = stringbuilder.toString(); 
     Log.v("HTTP UPLOAD REQUEST",result); 
     inputstream.close();  
     //handler.sendMessage(handler.obtainMessage());}
      }
     catch (Exception e) {
     e.printStackTrace();
     Toast.makeText(share.this, "Upload failed", Toast.LENGTH_SHORT).show();
    }
     Message msg = Message.obtainMessage();
     msg.arg1 = 1;
     handler.sendMessage(msg);

    }

    });

    background.start();
    }

    private final Handler handler = new Handler (){
    public void HandleMessage (Message msg){
         if(msg.arg1 == 1)
               dialog.dismiss();
    }
    };

Try like this

HttpResponse responsePOST = client.execute(httppost);  
 HttpEntity resEntity = responsePOST.getEntity(); 

 InputStream inputstream = resEntity.getContent();
 BufferedReader buffered = new BufferedReader(new InputStreamReader(inputstream));
 StringBuilder stringbuilder = new StringBuilder();
 String currentline = null; 

 while ((currentline = buffered.readLine()) != null)
    { 
     stringbuilder.append(currentline + "\n"); 
     String result = stringbuilder.toString(); 
     Log.v("HTTP UPLOAD REQUEST",result); 
     inputstream.close();  
     //handler.sendMessage(handler.obtainMessage());}
      }
     catch (Exception e) {
     e.printStackTrace();
     Toast.makeText(share.this, "Upload failed", Toast.LENGTH_SHORT).show();
    }
     Message msg = Message.obtainMessage();
     msg.arg1 = 1;
     handler.sendMessage(msg);

    }

    });

    background.start();
    }

    private final Handler handler = new Handler (){
    public void HandleMessage (Message msg){
         if(msg.arg1 == 1)
               dialog.dismiss();
    }
    };
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文