Android Question android.view.WindowManager$BadTokenException:

DMC

New Member
Licensed User
Getting error in playstore - android.view.WindowManager$BadTokenException:

I have uploaded the screenshot with full error here.

Any help will be appreciated. Thank you.
 

Attachments

  • Screen Shot 2018-09-27 at 11.20.29 am.png
    Screen Shot 2018-09-27 at 11.20.29 am.png
    200.5 KB · Views: 212

DMC

New Member
Licensed User
Hi DonManFred,

Thank you for replying. Please see the full error below I have published the app in PlayStore and app crashes as soon as it starts when we installed from play store. Please let me know if you require any further information. Thank you.
B4X:
android.view.WindowManager$BadTokenException:
  at android.view.ViewRootImpl.setView (ViewRootImpl.java:982)
  at android.view.WindowManagerGlobal.addView (WindowManagerGlobal.java:384)
  at android.view.WindowManagerImpl.addView (WindowManagerImpl.java:101)
  at android.app.Dialog.show (Dialog.java:430)
  at anywheresoftware.b4a.Msgbox.msgbox (Msgbox.java:169)
  at anywheresoftware.b4a.keywords.Common.Msgbox2 (Common.java:443)
  at anywheresoftware.b4a.keywords.Common.Msgbox (Common.java:422)
  at com.menzies.staystrong.starter._application_error (starter.java:166)
  at java.lang.reflect.Method.invoke (Native Method)
  at anywheresoftware.b4a.BA.raiseEvent2 (BA.java:191)
  at anywheresoftware.b4a.keywords.Common.CallSub4 (Common.java:1058)
  at anywheresoftware.b4a.keywords.Common.CallSubNew3 (Common.java:1021)
  at anywheresoftware.b4a.objects.ServiceHelper$StarterHelper.handleUncaughtException (ServiceHelper.java:251)
  at java.lang.reflect.Method.invoke (Native Method)
  at anywheresoftware.b4a.BA.raiseEvent2 (BA.java:217)
  at com.menzies.staystrong.main.afterFirstLayout (main.java:104)
  at com.menzies.staystrong.main.access$000 (main.java:17)
  at com.menzies.staystrong.main$WaitForLayout.run (main.java:82)
  at android.os.Handler.handleCallback (Handler.java:790)
  at android.os.Handler.dispatchMessage (Handler.java:99)
  at android.os.Looper.loop (Looper.java:164)
  at android.app.ActivityThread.main (ActivityThread.java:6960)
  at java.lang.reflect.Method.invoke (Native Method)
  at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run (RuntimeInit.java:441)
  at com.android.internal.os.ZygoteInit.main (ZygoteInit.java:1408)
 
Upvote 0

DonManfred

Expert
Licensed User
Please let me know if you require any further information
Does not look like a FULL error. It does not help.

Only i can say it sems to be related to MsgBox or a Modal dialog.
at anywheresoftware.b4a.Msgbox.msgbox (Msgbox.java:169)
Are you using async Dialogs?

Uploading an Project which shows the problem could help.
 
Upvote 0

DMC

New Member
Licensed User
Thank you Manfred. I got this error from GooglePlay Console > Crashes report. One of the app user using device Samsung Galaxy Tab S4 (gts4lwifi), Android 8.1 got this error. How do I replicate this error on my device as the app is paid and when I tested the app using B4A Bridge I did not receive any error. Please advice.

Also Yes, I am using Dialogs library ( Dialogs.jar,Dialogs.xml) in the app.
 
Upvote 0

DMC

New Member
Licensed User
Hi Erel,
Thank you for your reply. the problem was with runtime permission. I have modified my code to add runtime permission based on your tutorial. Please see my updated code below (I have changed database name and external folder name here). Would you please review it to see I have added code right way or not. Thanks in advance.

B4X:
    rp.CheckAndRequest(rp.PERMISSION_WRITE_EXTERNAL_STORAGE)
    rp.CheckAndRequest(rp.PERMISSION_CAMERA)
    Wait For Activity_PermissionResult (Permission As String, havePermission As Boolean)
    If havePermission = False Then
        ToastMessageShow("Sorry, can't continue, press button to try again.", True)
        Return
    End If
    
    If FirstTime Then
        If File.Exists(File.DirRootExternal, "mydatabasename.db") Then
            If File.Exists(File.DirDefaultExternal, "mydatabasename.db") = False Then
                File.Copy(File.DirRootExternal, "mydatabasename.db", File.DirDefaultExternal, "mydatabasename.db")
            End If
            File.Delete(File.DirRootExternal, "mydatabasename.db")
        End If
        If File.Exists(File.DirDefaultExternal, "mydatabasename.db") Then
            If File.Exists(File.DirRootExternal & "/My App Backup Folder", "") = False Then
                File.MakeDir(File.DirRootExternal, "My App Backup Folder")
            End If
            'File.Copy(File.DirDefaultExternal, "mydatabasename.db", File.DirRootExternal & "/My App Backup Folder", "mydatabasename.db." & DateTime.Now)
            File.Copy(rp.GetSafeDirDefaultExternal(""), "mydatabasename.db", rp.GetSafeDirDefaultExternal("My App Backup Folder"), "mydatabasename.db." & DateTime.Now)
            DoEvents
        End If
        'Starter.SQL1.Initialize(File.DirDefaultExternal, "mydatabasename.db", True)
        Starter.SQL1.Initialize(rp.GetSafeDirDefaultExternal(""), "mydatabasename.db", True)
        StartService(ScreenOnService)
    End If
 
Upvote 0
Top