0

I have below crash reported by a user of my app.

Caused by android.view.WindowManager$BadTokenException: Unable to add window -- token android.os.BinderProxy@56492cc is not valid; is your activity running?
       at android.view.ViewRootImpl.setView(ViewRootImpl.java:567)
       at android.view.WindowManagerGlobal.addView(WindowManagerGlobal.java:310)
       at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:85)
       at android.app.Dialog.show(Dialog.java:319)
       at android.app.ProgressDialog.show(ProgressDialog.java:116)
       at android.app.ProgressDialog.show(ProgressDialog.java:99)
       at com.my.app.MyActivity.reloadCardView(MyActivity.java:253)
       at com.my.app.MyActivity.refreshTable(MyActivity.java:247)
       at com.my.app.MyActivity.onCreate(MyActivity.java:133)
       ...
       ...

I am showing a ProgressDialog in in a method invoked from onCreate(). So, checking isFinishing() looks irrelevant to me.

So, what is the scenario where a crash like this can happen? I couldn't re-create this in my devices. Do I need to check isFinishing() before showing a progress dialog, even in onCreate()?

Lahiru Chandima
  • 22,324
  • 22
  • 103
  • 179
  • can the first answer in the following link https://stackoverflow.com/questions/18662239/android-view-windowmanagerbadtokenexception-unable-to-add-window-on-buider-s help you? – CodingLife Nov 29 '20 at 03:23
  • @CodingLife Since I am showing the dialog from `onCreate()`, it is in the main thread, not in a background thread. I need to know whether `isFinishing()` needs to be checked every time I am showing a dialog, even when I am sure it is not being called from some asynchronous callback. – Lahiru Chandima Nov 29 '20 at 03:28
  • can you share the code in onCreate()? – jana Nov 29 '20 at 06:28
  • Do you spawn any thread inside refreshTable() or refreshCardView() method? – Son Truong Nov 29 '20 at 10:53
  • @SonTruong No. Progress dialog is shown in the same thread on which `onCreate()` is called, as seen in the stack trace. There is an asynchronous task just after showing the progress dialog, but it doesn't get executed due to the exception. – Lahiru Chandima Nov 29 '20 at 12:41

0 Answers0