Android Question Timer ... trying to use it in a code module

artsoft

Active Member
Licensed User
Longtime User
Hi folks!

I want to protect my app while using a global timer. After 2 minutes without any action within the app, a special activity should be loaded and displayed.

B4X:
Sub Process_Globals
    'These global variables will be declared once when the application starts.
    'These variables can be accessed from all modules.
    
    Public globalTimer As Timer
    
End Sub

From my main activity I call this:

B4X:
Public Sub timerRenew()

    globalTimer.Initialize("globaltimer", 2 * 60000) ' 2 min
    globalTimer.Enabled = True
    
End Sub


Sub globaltimer_tick
    
    globalTimer.Enabled = False
    
    StartActivity(Protect)
    
End Sub

The problem is now, that my app could not find the "globaltimer_tick" sub.

What can I do in this case.

I could implement in each (!) activy the same code which several different timers. But this makes no sense in my case, because there so many activities in my app.

I want to have a global timer and a global tick event sub, which is able to load my "protect" activity in order to protect my app data.

Can anybody help here!

Thanks a lot in advance and best regards
ARTsoft
 

artsoft

Active Member
Licensed User
Longtime User
I forgot to say that this timer object is initialized in a code module not in a activity module.
 
Upvote 0

artsoft

Active Member
Licensed User
Longtime User
I get always this exception:

B4X:
java.lang.Exception: Sub globaltimer_tick was not found.
    at anywheresoftware.b4a.BA.raiseEvent2(BA.java:192)
    at anywheresoftware.b4a.objects.Timer$TickTack.run(Timer.java:105)
    at android.os.Handler.handleCallback(Handler.java:751)
    at android.os.Handler.dispatchMessage(Handler.java:95)
    at android.os.Looper.loop(Looper.java:154)
    at android.app.ActivityThread.main(ActivityThread.java:6682)
    at java.lang.reflect.Method.invoke(Native Method)
    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1520)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1410)
java.lang.Exception: Sub globaltimer_tick was not found.

:(
 
Upvote 0

artsoft

Active Member
Licensed User
Longtime User
Thanks LucaMS!

Ah ok, this makes sense. I will try this.

I dont know that code modules are so simple and not able to handle events.

Best regards
ARTsoft
 
Upvote 0
Top