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.
Dear Earl
My App has 3 activity and one service that must be run all time. I replaced the activities with the b4xpages. How I can replace the service with a b4xpage?
In the early days of Android services were simple to use and powerful. They allowed doing all kinds of things in the backgrounds with very few restrictions. That's not the case with newer versions of Android. With a few exceptions (that aren't 100% reliable), the only use case for services is to...
It actually depends on the reason for using a service. In many cases a B4XPage is the correct replacement for a service as B4XPages are not paused like activities.