Timer Tick Behaviour Erratic ??

MattLuckham

Member
Licensed User
Longtime User
Hi
I am having some strange behaviour that some of my users are reporting. We have a Basic4Android App which has a built in timeout functionality. The idea being that if the app is not use for a certain length of time (2 minutes) the app times out back to the initial login screen.

The code to support this time out is as follows: -

B4X:
Sub Process_Globals
   Dim InActivityCount As Long  'Declare global counter
End Sub
Sub Activity_Create(FirstTime As Boolean)
   If FirstTime Then
      Timer1.Initialize("Timer1", 5000) ' 1000 = 1 second
      Timer1.Enabled = False

   End If
End Sub

Start by initializing a timer which ticks every 5 seconds. However it is set to disabled to start with.

With our system the users enter a pin to log in. When they enter their pin the timer 1 is set to enabled = true.

The timer 1 tick code is as follows: -

B4X:
Sub Timer1_Tick
   InActivityCount = InActivityCount + 1
   If InActivityCount > 24 Then
         FinishButton_Click
   End If
End Sub

This means that every 5 seconds the timer adds one to the InActivityCount. That gives the user 2 minutes of possible activity.

Now, once the user has logged in there are various forms that interact with our database using an HTTP Post.

B4X:
Public Sub LoadBehaviourScreen()
Dim HTTPCall As HttpJob 


   HTTPCall.Initialize("BehaviourList",Me)
   HTTPCall.PostString("http://" & manager.GetString("CCIPAddress") & "/CareControl/CCResponse.aspx?TabletName=" & manager.GetString("CCTabletName") & "&Command=BehaviourList&Param1=&Param2=","")   
   
End Sub

When the HTTP JobDone is called back this is where I set the InActivityCount variable to 0: -

B4X:
InActivityCount = 0

So, the idea is that when the user loads a screen, which normally involves a HTTP call, the counter gets reset to 0 each time resetting the timer 1 event back to 2 minutes for user activity.

Some users are saying that the system is timing out whilst they are in a form. When I ask them how long they have been in a form they say only seconds!

Is it possible that the JobDone sub is clashing with the timer1 tick and that although it calls to set the InActivityCount to 0, in fact this is being overwritten by the timer1 tick? e.g. JobDone is called and tries to set InActivityCount = 0, but at same time timer1 tick is called and is already adding 1 to the current InActivityCount hence the counter is not reset?

I would say it is only happening 1 in 8 times of usage...
 

MattLuckham

Member
Licensed User
Longtime User
Timer 1 is declared in Process_Globals: -
I did not post all of the declarations as I thought it would not be relevant: -

B4X:
Sub Process_Globals

   Dim manager As PreferenceManager
   Dim screen As PreferenceScreen
   Dim Timer1 As Timer
   Dim Timer2 As Timer
   Dim VersionNumber As String 
   Dim InActivityCount As Long 
End Sub
 
Upvote 0

mc73

Well-Known Member
Licensed User
Longtime User
Where are you setting InActivityCount to zero, except from the jobDone sub? Note that since you are declaring in to process_globals, this will not reset itself upon activity_create (in case the activity is still alive by the os). I would choose to set InActivityCount=0 inside the timer's sub when it turns greater than 24.
 
Upvote 0

MattLuckham

Member
Licensed User
Longtime User
Thanks Guys. I think I will extend the timeout to 5 minutes. I am not convinced that the users are not staying on the same screen for 2 minutes. This would explain the issue.

In answer to you question mc73, that variable is reset when the sub FinishButton_Click is called (which is called from the timer event).

Thanks for your help though.
 
Upvote 0

mc73

Well-Known Member
Licensed User
Longtime User
An alternative way is to set time ticks at startup then check ticks inside the timer. This way, the activity_pause will be handled better maybe.
 
Upvote 0
Top