Android Question (Solved) Problem showing dialogs in a Class

Xicu

Active Member
Licensed User
Longtime User
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. ClsShowDialog Code:
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

  • ClassDialogProblem.zip
    39.4 KB · Views: 174
Last edited:

Xicu

Active Member
Licensed User
Longtime User
Even not classes initialized from a service.
I didn`t know this detail.
Conclusion: the classes that use Dialogs, must be initialize from an activity. (Never in services)
DonManfred, thank you very much (In activity works perfectly)
 
Last edited:
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…