码迷,mamicode.com
首页 > 其他好文 > 详细

Activity中异步操作showDialog异常解决方法:判断Ay是否结束

时间:2015-11-30 19:55:23      阅读:193      评论:0      收藏:0      [点我收藏+]

标签:

Android – Displaying Dialogs From Background Threads

判断一下Activity是否在finishing就好了,否则万一Activity销毁了,这个Dialog没有所依附的对象,就会有下面的异常抛出

private Handler myHandler = new Handler() {
  @Override
  public void handleMessage(Message msg) {
    switch (msg.what) {
      case DISPLAY_DLG:
        if (!isFinishing()) {
        showDialog(MY_DIALOG);
        }
      break;
    }
  }
};

android.view.WindowManager$BadTokenException: Unable to add window — token android.os.BinderProxy@447a6748 is not valid; is your activity running?
at android.view.ViewRoot.setView(ViewRoot.java:468)
at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:177)
at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:91)
at android.view.Window$LocalWindowManager.addView(Window.java:424)
at android.app.Dialog.show(Dialog.java:239)
at android.app.Activity.showDialog(Activity.java:2488)

at android.os.Handler.dispatchMessage(Handler.java:99)

Activity中异步操作showDialog异常解决方法:判断Ay是否结束

标签:

原文地址:http://www.cnblogs.com/permanent2012moira/p/5007833.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!