• <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)  編輯 收藏 引用

            日韩精品国产自在久久现线拍| 伊人丁香狠狠色综合久久| 久久影院亚洲一区| 久久久www免费人成精品| 亚洲AV日韩精品久久久久| 久久91精品国产91久久户| 久久不见久久见免费影院www日本| 青青热久久国产久精品 | 精品精品国产自在久久高清| 亚洲天堂久久精品| 亚洲欧美一区二区三区久久| 国产精品天天影视久久综合网| 久久精品成人免费观看97| 7777久久久国产精品消防器材| 情人伊人久久综合亚洲| 久久热这里只有精品在线观看| 婷婷综合久久狠狠色99h| 久久成人小视频| 精品久久久久久无码中文字幕| 久久婷婷五月综合97色| 国产精品99久久久久久宅男小说| 日韩一区二区久久久久久| 色综合久久中文字幕无码| 亚洲欧美另类日本久久国产真实乱对白| 久久久久久国产精品免费无码| 性欧美大战久久久久久久| 精品久久久久一区二区三区| AV无码久久久久不卡网站下载 | 久久A级毛片免费观看| 少妇被又大又粗又爽毛片久久黑人 | 久久婷婷国产综合精品| 久久这里的只有是精品23| 99久久综合狠狠综合久久| 久久久久免费看成人影片| 色综合久久久久综合99| 色8激情欧美成人久久综合电| 狠狠色综合网站久久久久久久 | 国产亚洲欧美精品久久久| 99蜜桃臀久久久欧美精品网站 | 99久久婷婷国产一区二区| 久久美女人爽女人爽|