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

            国产精品永久久久久久久久久| 久久er国产精品免费观看2| 欧美激情精品久久久久久久九九九| 99国内精品久久久久久久 | 亚洲精品午夜国产va久久| 久久综合亚洲色HEZYO社区| 日产精品久久久久久久| 国产精品免费看久久久香蕉| 欧美成人免费观看久久| 久久综合综合久久97色| 性高朝久久久久久久久久| 国产∨亚洲V天堂无码久久久| 久久AⅤ人妻少妇嫩草影院| 久久精品国产2020| 国产亚洲色婷婷久久99精品91| 久久精品人人做人人爽电影| 色综合久久综精品| 久久婷婷激情综合色综合俺也去| 久久久久香蕉视频| 久久99精品国产自在现线小黄鸭| 久久亚洲AV永久无码精品| 久久久久久久尹人综合网亚洲| 国产精品久久久久久久app | 欧美久久综合九色综合| 精品国产一区二区三区久久| 国内精品九九久久精品| 欧美久久久久久午夜精品| 国内精品久久久久影院免费| 中文国产成人精品久久不卡 | 狠狠色婷婷久久一区二区三区| 亚洲精品tv久久久久| 国产免费久久精品丫丫| 91精品国产综合久久四虎久久无码一级| 久久久这里有精品| 国内精品伊人久久久影院| 久久午夜福利电影| 久久99久久无码毛片一区二区| 久久国产精品-久久精品| 91久久精品国产成人久久| 97超级碰碰碰碰久久久久| 国产精品99久久精品爆乳|