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

            观看 国产综合久久久久鬼色 欧美 亚洲 一区二区 | 欧美国产成人久久精品| 亚洲精品NV久久久久久久久久| 亚洲国产日韩综合久久精品| 久久婷婷五月综合色奶水99啪| 99久久国产免费福利| 亚洲伊人久久成综合人影院 | 亚洲欧美日韩久久精品第一区| 国产精品美女久久久久久2018| 国产午夜精品理论片久久| 7777精品久久久大香线蕉 | 亚洲愉拍99热成人精品热久久| 一级做a爱片久久毛片| 亚洲精品无码久久一线| 久久久久国产一区二区三区| 久久国产亚洲精品无码| 久久精品中文字幕有码| 色综合久久中文色婷婷| 欧洲人妻丰满av无码久久不卡| 久久99精品国产麻豆蜜芽| 狠狠色婷婷久久一区二区三区| 久久人人爽人人人人爽AV| 精品国产91久久久久久久a| 国产91色综合久久免费| 热re99久久精品国99热| 国产偷久久久精品专区| 久久99国产精品久久99小说| 久久久久久毛片免费看| 久久91精品国产91久久户| 国内精品久久人妻互换| 国产精品久久久久久吹潮| 一本色综合网久久| 色婷婷综合久久久久中文| 亚洲AV无码久久精品成人| 久久久午夜精品| 亚洲国产精品一区二区三区久久 | 久久久久久无码国产精品中文字幕| av午夜福利一片免费看久久| 2020久久精品国产免费| 一级做a爱片久久毛片| 国产亚洲精久久久久久无码AV|