Android Question Problem with a timer

Alex_197

Well-Known Member
Licensed User
Longtime User
Hi all.

I have a small app (this is just an example) that does nothing but runs a timer.

It also has 2 activities and my code in Starter runs a timer that checks if both of theses activities are paused.

If so - let's wait for 10 seconds a show a message in a log Log("Log Out")

The idea is that if user has left for a while I want him to login back.

The problem is that the app finishes without any message and it can stop while counter is about 8 or 9. Never riches 10.

Here is a code

Starter code:
#Region  Service Attributes
    #StartAtBoot: False
    #ExcludeFromLibrary: True
#End Region

Sub Process_Globals
    'These global variables will be declared once when the application starts.
    'These variables can be accessed from all modules.
    Private Timer As Timer
    Private Counter As Int
End Sub

Sub Service_Create
    'This is the program entry point.
    'This is a good place to load resources that are not specific to a single activity.
    Timer.Initialize("Timer1",60000)
End Sub

Sub Service_Start (StartingIntent As Intent)
    Try
    
        Service.StopAutomaticForeground 'Starter service can start in the foreground state in some edge cases.
        Timer.Enabled=True
        
    Catch
        Log("Service_Start " & LastException)
    End Try
    
End Sub

Sub Service_TaskRemoved
    'This event will be raised when the user removes the app from the recent apps list.
    Try
        Log("Service_TaskRemoved")
    Catch
        Log("Service_TaskRemoved " & LastException)
    End Try
End Sub

'Return true to allow the OS default exceptions handler to handle the uncaught exception.
Sub Application_Error (Error As Exception, StackTrace As String) As Boolean
    
    Log(StackTrace & " " & Error.Message)
    
    Return True
    
End Sub

Sub Service_Destroy
    Try
        Log("Service_Destroy")
    Catch
        Log("Service_Destroy " & LastException)
    End Try
End Sub


private Sub RunCounter
    
    Try
        
        Dim IsP1 As Boolean
        Dim IsP2 As Boolean
        
        IsP1=IsPaused(Main)
        IsP2=IsPaused(screen2)
        
        
        Log("IsP1=" & IsP1 & " IsP2=" & IsP2)
        
        If IsP1 And IsP2  Then
            Counter = Counter + 1
            
            Log("Counter=" & Counter)
            
            If Counter = 10 Then               
                Log("Logged Out")               
            End If
        Else
            Counter = 0
        End If
    
    Catch
        Log("RunCounter " & LastException)
    End Try
    
End Sub

Sub timer1_tick
    
    Try
        RunCounter       
    Catch
        Log("timer1_tick " & LastException)
    End Try
    
    
End Sub

Please see this attached project.

Thanks.
 

Attachments

  • TimerTest.zip
    11.1 KB · Views: 355

Alex_197

Well-Known Member
Licensed User
Longtime User
You are waiting 10 minutes, not seconds. This is intentional?

Luca was faster than me...
Yes, Erel.

The idea is - user works with app. Then he put his phone on a table and left for a coffee for 30 minutes. After he came back - I want him to login again.

So I need to wait, if he is having conversation on a phone while running this app for 5 minutes all activities will be paused anyway and counter start counting minutes but once he finishes the conversation he can continue working because we counted only to 5. If it takes longer, let say 20 minutes or more - sorry, you need to login back.

The app should meet Department of Health requirements. It's not up to me.
 
Upvote 0

Alex_197

Well-Known Member
Licensed User
Longtime User
Ok. Your first post says 10 seconds.

What happens after you return back to your app after 10 minutes (and the timer stopped)? I expect Service_Create of the starter service to run again. Is that so?
10 seconds is just example

After 10 minutes get expired I'll erase a userID from a global variable and my code will close all the activities by using activity,finish and redirect user to the main login screen and - yes, Service_Create of the starter service to run again.
 
Upvote 0
Top