Android Question Fatal Exception: android.view.WindowManager$BadTokenException: Unable to add window -- token android.os.BinderProxy

AHilberink

Active Member
Licensed User
Longtime User
Hi,

I am getting this error from time to time:
B4X:
Fatal Exception: android.view.WindowManager$BadTokenException: Unable to add window -- token android.os.BinderProxy@97d5fc4 is not valid; is your activity running?
       at android.view.ViewRootImpl.setView(ViewRootImpl.java:1444)
       at android.view.WindowManagerGlobal.addView(WindowManagerGlobal.java:469)
       at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:114)
       at android.app.Dialog.show(Dialog.java:505)
       at android.app.ProgressDialog.show(ProgressDialog.java:225)
       at android.app.ProgressDialog.show(ProgressDialog.java:199)
       at anywheresoftware.b4a.keywords.Common.ProgressDialogShow2(Common.java:740)
       at anywheresoftware.b4a.keywords.Common.ProgressDialogShow(Common.java:729)
       at ciris.chauffeur.synchroniseer._maaksynchroon(synchroniseer.java:403)
       at java.lang.reflect.Method.invoke(Method.java)
       at anywheresoftware.b4a.BA.raiseEvent2(BA.java:213)
       at anywheresoftware.b4a.keywords.Common$11.run(Common.java:1178)
       at android.os.Handler.handleCallback(Handler.java:938)
       at android.os.Handler.dispatchMessage(Handler.java:99)
       at android.os.Looper.loop(Looper.java:246)
       at android.app.ActivityThread.main(ActivityThread.java:8538)
       at java.lang.reflect.Method.invoke(Method.java)
       at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:602)
       at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1130)

My code is:
B4X:
Public Sub MaakSynchroon
    ProgressDialogShow("Synchroniseren")
    RunningEnd=5
    Running=0
    OphalenLogo2(False)
    OphalenKantoor(False)
    OphalenKentekens2("A",False)
    OphalenKentekens2("C",False)
    OphalenKentekens2("K",False)
    OphalenMedewerkers
    WachtrijReset
    Starter.Nogmaals=False
    Starter.BezigMetOphalen=False
    Starter.OphalenMessages
End Sub

and is starterted from code:
B4X:
Sub imvSynch_Click
    StateManager.RestoreState(Activity, "Hoofdscherm", 0)
    pnlWeging.Top=TopWeging
    StopService(GPSLocatie)   
    CallSubDelayed(Synchroniseer,"MaakSynchroon")
End Sub

Can someone tell me why this happening from time to time and what I can do to prevent this?
Normaly the imvSynch_Click is working fine.

Kind regards,
André
 

AHilberink

Active Member
Licensed User
Longtime User
It is an Activity Module, not a service.

May be this will help:
B4X:
Public Sub MaakSynchroon
    ProgressDialogShow("Synchroniseren")
    RunningEnd=5
    Running=0
    OphalenLogo2(False)
    OphalenKantoor(False)
    OphalenKentekens2("A",False)
    OphalenKentekens2("C",False)
    OphalenKentekens2("K",False)
    OphalenMedewerkers
    WachtrijReset
    Starter.Nogmaals=False
    Starter.BezigMetOphalen=False
    ProgressDialogHide
    Starter.OphalenMessages
End Sub

Added ProgressDialogHide before running a Sub from Starter service?

I will try......
 
Upvote 0

AHilberink

Active Member
Licensed User
Longtime User
Somehow the activity isn't running or isn't ready when you call ProgressDialogShow.

You can catch this error. Adding Sleep(0) might also help.

You mean like this:
B4X:
Public Sub MaakSynchroon
    Sleep(0)
    Try
        ProgressDialogShow("Synchroniseren")
    Catch
        Log(LastException)
    End Try
    RunningEnd=5
    Running=0
    OphalenLogo2(False)
    OphalenKantoor(False)
    OphalenKentekens2("A",False)
    OphalenKentekens2("C",False)
    OphalenKentekens2("K",False)
    OphalenMedewerkers
    WachtrijReset
    Starter.Nogmaals=False
    Starter.BezigMetOphalen=False
    Starter.OphalenMessages
End Sub
 
Upvote 0
Top