我正在使用b4a [Basic4Android],并且已经在论坛上进行搜索,所有答案都与Android Studio有关。
我的代码在android <4 [Emulator]上运行良好,但是无论何时在android上运行,我都使用toastmessageshowlibrary v2.0。
Ignoring event as service was destroyed: autodiscoverudpsocket_packetarrived
android.view.WindowManager$BadTokenException: Unable to add window -- token
null is not valid; is your activity running?
at android.view.ViewRootImpl.setView(ViewRootImpl.java:790)
at android.view.WindowManagerGlobal.addView(WindowManagerGlobal.java:374)
at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:93)
at anywheresoftware.it.giuseppe.salvi.notification.core.ToastShowWrapper$ToastManager.display(ToastShowWrapper.java:1515)
at anywheresoftware.it.giuseppe.salvi.notification.core.ToastShowWrapper$ToastManager.handleMessage(ToastShowWrapper.java:1494)
at android.os.Handler.dispatchMessage(Handler.java:106)
at android.os.Looper.loop(Looper.java:164)
at android.app.ActivityThread.main(ActivityThread.java:6524)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:438)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:888)
我在子全局变量下声明了mymsgbox。
我的B4a代码是:
Sub Activity_Create(FirstTime As Boolean)
Try
Activity.LoadLayout("splash")
mymsgbox.Initialize("mymsgbox")
btnsplashlogin.Width = 65%X
StartService(Starter)
token = "KPOPULARisaccessingitsserverfromapp"
data = bconv.StringToBytes(token, "UTF8")
data = md.GetMessageDigest(data, "SHA-1")
token= (bconv.HexFromBytes(data))
token = token&token
data = bconv.StringToBytes(token, "UTF8")
data = md.GetMessageDigest(data, "SHA-1")
token = bconv.HexFromBytes(data)
Sleep(10)
btnsplashlogin.Top = 50%Y
btnsplashregister.Width = 65%X
btnsplashregister.Top = 59%Y
lblcybtech.Left= 0%x
lblcybtech.Top = 90%y
lblcybtech.Width = 100%x
DisableStrictMode
registerlogindesign
StartService(Starter)
rpermission.CheckAndRequest(rpermission.PERMISSION_CALL_PHONE)
rpermission.CheckAndRequest(rpermission.PERMISSION_READ_EXTERNAL_STORAGE)
rpermission.CheckAndRequest(rpermission.PERMISSION_WRITE_EXTERNAL_STORAGE)
rpermission.CheckAndRequest(rpermission.PERMISSION_READ_PHONE_STATE)
homelink= enc.DecodeStoS("aHR0cDovLzE3Mi4xNy4xMDAuMi9rcC8=", "UTF8")
homelink= enc.DecodeStoS("aHR0cDovL2t3YXN1cG9wdWxhci4wMDB3ZWJob3N0YXBwLmNvbS9rcC8=F", "UTF8")
wait for activity_permissionresult (Permission As String, Result As Boolean)
If Result = True Then
If File.Exists(File.DirInternal,"reg") = True Then
Activity.Finish
StartActivity(menu)
Else
btnsplashlogin.SetVisibleAnimated(500,True)
Sleep(500)
btnsplashregister.SetVisibleAnimated(500,True)
Sleep(500)
lblcybtech.SetVisibleAnimated(300,True)
If File.Exists(File.DirInternal,"reg") = False Then
mymsgbox.Initialize("mymsgbox")
mymsgboxtext = "Welcome, Please register or login.."
mymsgboxshow
End If
End If
If Result = False Then
Msgbox("You need to allow all permissions, to continue..",title)
ExitApplication
End If
End If
Catch
mymsgboxtext = "An error has occured."
mymsgboxshow2
End Try
End Sub
这是导致问题的原因。
mymsgboxtext = "Welcome, Please register or login.."
mymsgboxshow