It would probably be stupid or a concept problem.
I have a class with a method called ShowDialog which it loads a Msgbox.
I declare a public instance in the starter service.
If I initialize it in Main, and I call the ShowDialog method it's displayed correctly.
But if I initialize it in StarterService (in Service_Start), and call Showdialog in Main, this error is triggered.
Starter code:
Main Code:
Why does it happen? Any idea? Thanks in advance
I include the project:
I have a class with a method called ShowDialog which it loads a Msgbox.
I declare a public instance in the starter service.
If I initialize it in Main, and I call the ShowDialog method it's displayed correctly.
But if I initialize it in StarterService (in Service_Start), and call Showdialog in Main, this error is triggered.
ClsShowDialog Code:Error occurred on line: 10 (ClsShowDialog)
android.view.WindowManager$BadTokenException: Unable to add window -- token null is not for an application
at android.view.ViewRootImpl.setView(ViewRootImpl.java:683)
at android.view.WindowManagerGlobal.addView(WindowManagerGlobal.java:342)
at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:94)
.....
B4X:
Sub Class_Globals
End Sub
Public Sub Initialize
End Sub
Public Sub ShowDialog
Msgbox("Hello world", "HELLO")
End Sub
Starter code:
B4X:
Sub Process_Globals
Public MainClass As ClsShowDialog
Public StarterClass As ClsShowDialog
End Sub
Sub Service_Create
End Sub
Sub Service_Start (StartingIntent As Intent)
StarterClass.Initialize
End Sub
Main Code:
B4X:
Sub Process_Globals
End Sub
Sub Globals
Private BtnStarterClass As Button
Private BtnMainClass As Button
End Sub
Sub Activity_Create(FirstTime As Boolean)
'Do not forget to load the layout file created with the visual designer. For example:
Starter.MainClass.Initialize
Activity.LoadLayout("main")
End Sub
Sub Activity_Resume
End Sub
Sub Activity_Pause (UserClosed As Boolean)
End Sub
Sub BtnStarterClass_Click
Starter.StarterClass.ShowDialog
End Sub
Sub BtnMainClass_Click
Starter.MainClass.ShowDialog
End Sub
Why does it happen? Any idea? Thanks in advance
I include the project:
Attachments
Last edited: