• <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)計(jì)

            最新評論

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


            只有注冊用戶登錄后才能發(fā)表評論。
            網(wǎng)站導(dǎo)航: 博客園   IT新聞   BlogJava   博問   Chat2DB   管理


            成人a毛片久久免费播放| 波多野结衣AV无码久久一区| 久久久久久久久久免免费精品| 丁香色欲久久久久久综合网| 思思久久99热只有频精品66| 久久久久国产视频电影| 久久久久女教师免费一区| 国产99久久久久久免费看| 久久精品国产免费| 97精品国产97久久久久久免费| 久久91综合国产91久久精品| 热久久这里只有精品| 久久久久久综合一区中文字幕| 一级做a爱片久久毛片| 亚洲一区中文字幕久久| 久久99国产精品久久99果冻传媒| 国内精品久久久久久野外| 无码AV中文字幕久久专区| www.久久热.com| 99久久夜色精品国产网站| 久久亚洲AV永久无码精品| 国产精品中文久久久久久久| 国色天香久久久久久久小说 | 亚洲欧美久久久久9999| 国产精品久久久久久久app| 国产精品一区二区久久精品涩爱 | 久久久久久人妻无码| 久久久亚洲欧洲日产国码aⅴ| 国产精品美女久久久久| 国产免费久久精品丫丫| 亚洲欧美成人久久综合中文网 | 91精品国产高清91久久久久久| 欧美一区二区精品久久| 久久久精品日本一区二区三区| 麻豆成人久久精品二区三区免费| 久久人人爽人人爽人人片AV不| 精品久久久噜噜噜久久久| 久久笫一福利免费导航 | 久久久久亚洲AV无码永不| 国产一区二区精品久久岳| 亚洲国产成人精品久久久国产成人一区二区三区综 |