Hi
My B4A app has two activities, one of which has a timer, which executes its subroutine every 1 sec. The problem is that when I am in the other activity, the timer does not stop, and every second the program returns to the timer activity and executes its subroutine.
Can everyone know the solution?
- Stop the time when you reach Activity_Pause. Start the timer in Activity_Resume
B4X:
Sub Activity_Create(FirstTime As Boolean)
'Do not forget to load the layout file created with the visual designer. For example:
Activity.LoadLayout("Layout1")
timer1.Initialize("Timer",1000)
End Sub
Sub Activity_Pause (UserClosed As Boolean)
timer1.Enabled = False
End Sub
Sub Activity_Resume
timer1.Enabled = True
End Sub
Sub Timer_Tick
Log($"Timer-Tick"$)
End Sub
When you switch to second activity the timer ill be stopped. When you come back to actitiy 1 it will be restartet...
I strongly recommend to switch to B4XPages. Things will simply work as you expect and you will not need to deal with the many challenges related to the complex activities life cycle.
- Stop the time when you reach Activity_Pause. Start the timer in Activity_Resume
B4X:
Sub Activity_Create(FirstTime As Boolean)
'Do not forget to load the layout file created with the visual designer. For example:
Activity.LoadLayout("Layout1")
timer1.Initialize("Timer",1000)
End Sub
Sub Activity_Pause (UserClosed As Boolean)
timer1.Enabled = False
End Sub
Sub Activity_Resume
timer1.Enabled = True
End Sub
Sub Timer_Tick
Log($"Timer-Tick"$)
End Sub
When you switch to second activity the timer ill be stopped. When you come back to actitiy 1 it will be restartet...
I strongly recommend to switch to B4XPages. Things will simply work as you expect and you will not need to deal with the many challenges related to the complex activities life cycle.
I strongly recommend to switch to B4XPages. Things will simply work as you expect and you will not need to deal with the many challenges related to the complex activities life cycle.