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

            久久精品aⅴ无码中文字字幕不卡 久久精品aⅴ无码中文字字幕重口 | 国产精品一久久香蕉国产线看| 久久精品国产99国产精品导航| 一本久道久久综合狠狠爱| 色妞色综合久久夜夜| 国产综合久久久久久鬼色| 久久久久无码精品| 久久精品aⅴ无码中文字字幕不卡| 激情五月综合综合久久69| 97久久精品人妻人人搡人人玩| 久久人妻少妇嫩草AV无码蜜桃| 无码日韩人妻精品久久蜜桃| 久久精品无码一区二区日韩AV | 91视频国产91久久久| 久久久无码精品亚洲日韩软件| 久久精品国产清高在天天线| 欧美性猛交xxxx免费看久久久| 国产精品禁18久久久夂久| 性高朝久久久久久久久久| 99久久国产综合精品五月天喷水 | 欧美日韩精品久久免费| 中文精品久久久久国产网址| 91精品国产高清91久久久久久| 久久99久国产麻精品66| 日本WV一本一道久久香蕉| 久久久久久久国产免费看| 一本大道加勒比久久综合| 国产精品久久国产精品99盘 | 97超级碰碰碰久久久久| 亚洲色欲久久久综合网| 国产69精品久久久久久人妻精品| 亚洲欧美日韩久久精品| 亚洲国产成人久久综合一区77 | 精品久久久一二三区| 亚洲а∨天堂久久精品| 亚洲?V乱码久久精品蜜桃| 综合久久一区二区三区 | 国产精品gz久久久| 欧美日韩精品久久久久| 四虎影视久久久免费| 日产精品久久久久久久|