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

            久久99热这里只有精品国产| 久久婷婷色综合一区二区| 伊人久久大香线蕉综合Av| 亚洲午夜久久久久久久久电影网| 久久精品成人欧美大片| 久久精品中文闷骚内射| 免费观看成人久久网免费观看| 国内精品久久久久久久涩爱| 亚洲国产视频久久| 国产一级做a爰片久久毛片| 久久人人爽人爽人人爽av| 久久综合噜噜激激的五月天| 91超碰碰碰碰久久久久久综合| 亚洲人成无码网站久久99热国产| 久久精品天天中文字幕人妻| 一本大道加勒比久久综合| 97精品依人久久久大香线蕉97 | 伊人久久五月天| 久久国产免费观看精品3| 亚洲午夜久久久| 狠狠色丁香婷婷综合久久来来去 | 一级做a爱片久久毛片| 久久精品中文字幕一区| 久久996热精品xxxx| 久久精品这里热有精品| 亚洲国产精品无码久久98| 欧美一级久久久久久久大片| 久久精品国产亚洲麻豆| 国内精品久久人妻互换| 一本一本久久A久久综合精品| 日韩中文久久| 久久久久人妻精品一区三寸蜜桃| 久久午夜电影网| 久久久青草青青亚洲国产免观| 久久精品人人槡人妻人人玩AV| 欧美黑人激情性久久| 一级a性色生活片久久无少妇一级婬片免费放 | 亚州日韩精品专区久久久| 国产女人aaa级久久久级| 香蕉久久夜色精品国产小说| 久久夜色精品国产亚洲|