• <ins id="pjuwb"></ins>
    <blockquote id="pjuwb"><pre id="pjuwb"></pre></blockquote>
    <noscript id="pjuwb"></noscript>
          <sup id="pjuwb"><pre id="pjuwb"></pre></sup>
            <dd id="pjuwb"></dd>
            <abbr id="pjuwb"></abbr>

            大龍的博客

            常用鏈接

            統計

            最新評論

            Android: annoying exception Unable to add window – is your activity running? --- 轉

            After publishing one of our apps on Google Play market I started receiving strange exception on Play Console:

            android.view.WindowManager$BadTokenException: Unable to add window -- token android.os.BinderProxy@40b47bd8 is not valid; is your activity running?
            at android.view.ViewRoot.setView(ViewRoot.java:452)
            at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:283)
            at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:193)
            at android.view.WindowManagerImpl$CompatModeWrapper.addView(WindowManagerImpl.java:118)
            at android.view.Window$LocalWindowManager.addView(Window.java:532)
            at android.app.Dialog.show(Dialog.java:269)
            ...

            This exception occurred while app was trying to notify user from the background thread by opening a Dialog.

            I could not reproduce it myself: I tried every device I had and every type of emulator I could think of, but no luck, the app worked just fine. However, according to Google Play console, exception occurred very often and seemed very consistent.

            After doing some research I found out that it is possible for my app to try notifying the user while being in the background (device screen is locked, app is sent to background with home button).

            So I looked at Android docs on Activity and discovered a very useful method – isFinishing() which is called by Android when Activity enters finishing stage: be it explicit finish() call or activity clean up made by Android.

            Using that flag it is very easy to avoid opening dialog from background thread when Activity is finishing:

            runOnUiThread(new Runnable() {
               @Override
               public void run() {
                if(!isFinishing()){
                    showDialog (
                                new AlertDialog.Builder(MainActivity.this)
                            .setTitle(R.string.dialogTitle)
                            .setMessage(R.string.dialogText)
                            .setCancelable(false)
                            .setPositiveButton(R.string.txtOk,
                            new OnClickListener() {
                                @Override
                                public void onClick(DialogInterface dialog, int which) {
                                                      // whatever...                        
                                }
                            })
                            .create()
                             );
                   }
               }
            });

             

            As you can see – the fix is very simple and straightforward: just check if your Activity is going to finish before opening dialog.

            posted on 2012-09-19 00:03 大龍 閱讀(1149) 評論(0)  編輯 收藏 引用

            91精品国产乱码久久久久久| 久久夜色精品国产亚洲| 国产精品xxxx国产喷水亚洲国产精品无码久久一区 | 久久伊人五月丁香狠狠色| 国产毛片欧美毛片久久久| 亚洲AV乱码久久精品蜜桃| 国产精品美女久久久m| 国产高清国内精品福利99久久| 国产999精品久久久久久| 久久精品国产精品亚洲| 狠狠色综合网站久久久久久久高清| 中文精品久久久久人妻不卡| 99国产精品久久久久久久成人热| 99久久免费只有精品国产| 亚洲国产视频久久| 青青国产成人久久91网| 久久久精品久久久久影院| 国产精品久久成人影院| 免费精品国产日韩热久久| 久久久精品免费国产四虎| 久久精品国产久精国产果冻传媒| 久久最近最新中文字幕大全| 色狠狠久久综合网| 精品国产一区二区三区久久蜜臀| 亚洲av成人无码久久精品| 久久久无码精品亚洲日韩软件| 97r久久精品国产99国产精| 99久久国产亚洲综合精品| 亚洲国产天堂久久综合网站| 午夜精品久久久久久久久| 日韩欧美亚洲国产精品字幕久久久| 国产精品99久久99久久久| 婷婷久久五月天| 精品无码久久久久久久动漫| 久久中文字幕一区二区| 精品久久久久久综合日本| 久久综合88熟人妻| 久久国产精品99国产精| 亚洲精品无码久久久久去q| 久久免费看黄a级毛片| 偷偷做久久久久网站|