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

            国产精品久久久久a影院| 久久久国产精品福利免费| 欧美久久综合九色综合| 怡红院日本一道日本久久| 国产精品熟女福利久久AV| 久久精品极品盛宴观看| 影音先锋女人AV鲁色资源网久久| 久久亚洲精精品中文字幕| 久久国产免费| 91精品国产色综合久久| 久久久久亚洲AV成人网人人网站| 99精品久久精品一区二区| 伊人色综合久久| 久久人爽人人爽人人片AV| 久久久久国产一级毛片高清板| 亚洲中文字幕无码久久2017| 久久综合九色综合97_久久久| 区久久AAA片69亚洲| 国产99久久久国产精品~~牛| 久久午夜福利无码1000合集| 精品久久久久久国产牛牛app| 久久久久亚洲av无码专区导航| 亚洲欧美久久久久9999| 国产精品99久久久久久www| 国产成人精品综合久久久久| 久久性精品| 久久综合成人网| 久久93精品国产91久久综合| 久久久久夜夜夜精品国产| 久久久久亚洲AV无码专区体验| 国产精品久久久久久五月尺| 久久亚洲AV无码西西人体| 久久亚洲高清综合| 久久本道久久综合伊人| 亚洲嫩草影院久久精品| 久久久九九有精品国产| 久久精品国产免费| 99久久精品国产一区二区| 久久久精品国产亚洲成人满18免费网站 | 中文国产成人精品久久不卡| 亚洲Av无码国产情品久久|