Hi all.
I've been working on my project that requires the app to run the timer when the app is in Inactive mode - when event App_Inactive fired.
Please see my main module code. I also attached my project.
Thank you.
I've been working on my project that requires the app to run the timer when the app is in Inactive mode - when event App_Inactive fired.
Please see my main module code. I also attached my project.
Timer:
Sub Process_Globals
'These global variables will be declared once when the application starts.
'Public variables can be accessed from all modules.
Public App As Application
Public NavControl As NavigationController
Private Page1 As Page
Private Timer1 As Timer
Private strTimeFormatShow As String="hh:mm a"
Private strDateFormat As String="MM/dd/yyyy"
Private Flag As Boolean=False
Private Counter As Int
Private txtLog As TextView
Private lblVer As Label
Private btnSave As Button
End Sub
Private Sub Application_Start (Nav As NavigationController)
NavControl = Nav
Page1.Initialize("Page1")
Page1.RootPanel.LoadLayout("Page1")
NavControl.ShowPage(Page1)
DateTime.DateFormat=strDateFormat
DateTime.TimeFormat=strTimeFormatShow
lblVer.Text="01.01 11/21/2020"
Timer1.Initialize("Timer1", 60000)
Timer1.Enabled=True
ReadLog
Dim DeviceID As String=""
DeviceID="DeviceID=" & GetVendorIdentifier
lblVer.Text=lblVer.Text & CRLF & DeviceID
End Sub
Private Sub Page1_Resize(Width As Int, Height As Int)
End Sub
Private Sub Application_Background
Flag=True
Log("We are in background" & TAB & Today & TAB & Now & CRLF & "Timer is ticking")
ShowLog("We are in background" & TAB & Today & TAB & Now & CRLF & "Timer is ticking")
End Sub
Private Sub Application_Inactive
Flag=True
Log("We are Inactive" & TAB & Today & TAB & Now)
ShowLog("We are Inactive" & TAB & Today & TAB & Now)
End Sub
Private Sub Application_Active
Flag=False
Log("We are active" & TAB & Today & TAB & Now)
ShowLog("We are active" & TAB & Today & TAB & Now)
End Sub
private Sub Application_Foreground
Flag=False
Log("Application_Foreground" & TAB & Today & TAB & Now )
ShowLog("Application_Foreground" & TAB & Today & TAB & Now )
End Sub
Private Sub Timer1_Tick
Log("Now=" & Now)
RunCounter
End Sub
Private Sub RunCounter
Log("Flag=" & Flag & TAB & Now)
ShowLog("Flag=" & Flag & TAB & Now)
If Flag=False Then
Counter=0
Return
End If
Counter=Counter+1
Log(Now & TAB & "Counter=" & Counter)
ShowLog(Now & TAB & "Counter=" & Counter)
If Counter=5 Then
Log("Time has expired")
ShowLog("Time has expired")
Counter=0
End If
End Sub
private Sub Today As String
Return DateTime.Date(DateTime.Now)
End Sub
private Sub Now As String
Return DateTime.Time(DateTime.Now)
End Sub
Private Sub ShowLog(str As String)
Try
txtLog.Text=txtLog.Text & CRLF & str
Catch
Log("ShowLog " & LastException)
End Try
End Sub
Private Sub ReadLog
Try
If File.Exists(File.DirDocuments,"log.txt") Then
Log("Exists")
Dim str As String
str=File.ReadString(File.DirDocuments,"log.txt")
Log("ReadLog " & str)
Else
Log("Doesn't Exist")
End If
Catch
Log(LastException)
End Try
End Sub
Sub btnSave_Click
Try
Dim out As OutputStream
out=File.OpenOutput(File.DirDocuments,"log.txt",True)
File.WriteString(File.DirDocuments,"log.txt",txtLog.Text)
out.Close
Msgbox("Saved","Test")
Catch
Log(LastException)
End Try
End Sub
Sub GetVendorIdentifier As String
Dim no As NativeObject
no = no.Initialize("UIDevice").RunMethod("currentDevice", Null)
Dim id As Object = no.GetField("identifierForVendor").GetField("UUIDString")
Return id
End Sub
Thank you.
Attachments
Last edited: