• <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>

            大龍的博客

            常用鏈接

            統(tǒng)計

            最新評論

            Android: annoying exception Unable to add window – is your activity running? --- 轉(zhuǎn)

            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 大龍 閱讀(1154) 評論(0)  編輯 收藏 引用

            久久一区二区三区免费| 久久精品国产色蜜蜜麻豆| 99久久婷婷国产综合精品草原| 93精91精品国产综合久久香蕉 | 国产综合成人久久大片91| 亚洲国产成人久久笫一页| 久久精品国产亚洲AV无码娇色 | 欧美va久久久噜噜噜久久| 亚洲午夜久久久精品影院| 97精品伊人久久久大香线蕉| 香蕉久久夜色精品国产小说| 伊人久久综合无码成人网| 国产精品青草久久久久福利99| 嫩草伊人久久精品少妇AV| 亚洲а∨天堂久久精品9966| 久久久久夜夜夜精品国产| 久久久久久久久久久久中文字幕| 久久人人爽人爽人人爽av | 久久无码AV中文出轨人妻| 久久国产高清字幕中文| 色偷偷久久一区二区三区| 无码人妻久久一区二区三区蜜桃| 狠狠人妻久久久久久综合蜜桃 | 狠狠色丁香久久婷婷综合蜜芽五月 | 99久久精品无码一区二区毛片| 欧美大香线蕉线伊人久久| 久久综合鬼色88久久精品综合自在自线噜噜| 国产精品18久久久久久vr| 激情伊人五月天久久综合| 99热成人精品热久久669| 日韩av无码久久精品免费| 亚洲午夜精品久久久久久浪潮| 久久丝袜精品中文字幕| 狠狠色伊人久久精品综合网| 久久精品国产一区二区三区| 国产福利电影一区二区三区,免费久久久久久久精 | 99久久精品影院老鸭窝| 久久精品国产一区| 国产精品综合久久第一页| 久久久久亚洲AV成人网人人软件| 久久人搡人人玩人妻精品首页|