Android Question looping between time

apty

Active Member
Licensed User
Longtime User
Is it possible to loop between time? e.g i want to write to a file from 2pm to 4pm. I want to stop writing when it reaches 4pm.
Any suggestions will be appreciated.
 

apty

Active Member
Licensed User
Longtime User
Thanks Erel,
I have been trying to use a timer but how do i loop say from 2pm to 4 pm? This is my code
B4X:
Sub timer1_Tick

  For i = 1 To 10
      WriteTextWriter(Ax&","&Ay&","&Az&","&datetoday&","&lblBattery.Text&",IMEI="&imei)
  Next
End Sub
If i use an if statement, the statement keeps executing even after 4pm. Also, i tried with a service and the service doesn't stop at 4pm, it still writes the file.Please help.
 
Upvote 0

apty

Active Member
Licensed User
Longtime User
Tried the code below but it doesnt work
B4X:
Sub Service_Start (StartingIntent As Intent)
    Dim timenow,timenow2 As String
    DateTime.TimeFormat="HH:mm"
    timenow=DateTime.time(DateTime.Now)
    timenow2=timenow.Replace(":",".")
    Dim starttime2 As Double=main.starttime2
    Dim endtime2 As Double=main.endtime2
    If timenow2>=starttime2 AND timenow2<=endtime2 Then
  
    timer1.Enabled=True
  
    Else
    timer1.Enabled=False
    End If
  
End Sub

The timer is not enabled If i remove the if statement, the timer works
 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…