使用处理程序结束进度对话框
我需要知道如何在 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
尝试这样
Try like this