Android Question Starter process globals not recognized in main module

Startup

Active Member
Licensed User
Longtime User
I'm trying to use a starter module to declare and initialize process globals and initialize them in the starter module like this --
B4X:
 Sub Process_Globals
    Public Timer1 As Timer
End Sub

Sub Service_Create
        Timer1.Initialize("Timer1",2000)
     Timer1.Enabled=True   
End Sub

yet in the main module where I have
B4X:
Sub Timer1_Tick
    Msgbox("Times Up","")
    Timer1.Enabled=False
End Sub

I get a "undeclared timer1 ... " message.
How do I get the starter globals recognized in the main module?
 

DonManfred

Expert
Licensed User
Longtime User
Maybe i´m wrong but shouldn´t the timer tick not be in the starter service instead of the main module?
 
Upvote 0

Startup

Active Member
Licensed User
Longtime User
The correct code:
B4X:
Starter.Timer1.Enabled = True
OK Erel that gets rid of the "undeclared" message. But I have to move the initialization to the main module to make it work but I read that initialization should be in the starter service module? I also tried to move the timer tick into the starter service per Don Manfred's post below but that didn't work for me . I'm just using this simple program to learn what to put in the starter module and what in the main. Here is my code in zip file. This works but I don't think it is right way (or elegant way - initialization should be in the starter modue?). Or is this the best way to do it? Thanks!
 

Attachments

  • MyServiceTest.zip
    6.5 KB · Views: 170
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
Technically it is not important whether the timer is declared in the process_globals of the starter service or the main activity.
The result is exactly the same.

If you want to use the timer from the main module then it should be private and declared in the main module, and initialized when FirstTime is true.

If you want to use it from the starter service then it should be private and declared in the starter service, and initialized in Service_Create.

Both options are good.
 
Upvote 0
Top