Android ProgessDialog奇怪的控制台错误消息

时间:2016-09-25 14:38:53

标签: java android

我有一个简单的ProgessDialog。我显示对话框,调用方法,然后在方法内部隐藏对话框,但是我收到控制台错误。

ProgressDialog progressDialog = new ProgressDialog(ChangeEmailActivity.this);
progressDialog.setTitle("Loading");
progressDialog.show();

方法内部

progressDialog.hide();
  

E / WindowManager:android.view.WindowLeaked:Activity de.at_c.liftkey.ChangeEmailActivity已泄露窗口com.android.internal.policy.impl.PhoneWindow $ DecorView {10f2f3a8 GE .... R ..... ID 0,0-729,322}最初是在这里添加的                                                                     在android.view.ViewRootImpl。(ViewRootImpl.java:363)                                                                     在android.view.WindowManagerGlobal.addView(WindowManagerGlobal.java:271)                                                                     在android.view.WindowManagerImpl.addView(WindowManagerImpl.java:85)                                                                     在android.app.Dialog.show(Dialog.java:298)                                                                     at de.at_c.liftkey.ChangeEmailActivity $ 1.onClick(ChangeEmailActivity.java:42)                                                                     在android.view.View.performClick(View.java:4780)                                                                     在android.view.View $ PerformClick.run(View.java:19866)                                                                     在android.os.Handler.handleCallback(Handler.java:739)                                                                     在android.os.Handler.dispatchMessage(Handler.java:95)                                                                     在android.os.Looper.loop(Looper.java:135)                                                                     在android.app.ActivityThread.main(ActivityThread.java:5254)                                                                     at java.lang.reflect.Method.invoke(Native Method)                                                                     在java.lang.reflect.Method.invoke(Method.java:372)                                                                     在com.android.internal.os.ZygoteInit $ MethodAndArgsCaller.run(ZygoteInit.java:903)                                                                     在com.android.internal.os.ZygoteInit.main(ZygoteInit.java:698)

2 个答案:

答案 0 :(得分:0)

使用

progressDialog.dismiss();

而不是

progressDialog.hide();

您需要关闭对话框而不是隐藏它。

答案 1 :(得分:0)

尝试在保存活动或片段之前运行progressBar.dismiss()。总是可以把它放在onDestroy()方法中。