Android Question "auto refresh" Android tablet

AKJammer

Active Member
Licensed User
Hey All,
I'm working on a project that requires the tablet to refresh the screen without user input if data changes. How I've implemented it is a field in the database that, if set to '1', will trigger a call to the refresh button that is available to the user. If RefreshBtn is pressed, the first thing it does is goes to the database and sets the flag to '0'. This is all handled within a check refresh subroutine that polls the database every variable (currently 10) seconds. The problem I have is that it works just fine when I'm debugging and have the tablet connected via bridge, but once I put the code in Release mode and copy it over to another tablet, the refresh never happens. The database flag stays set to '1'. If I do a manual refresh, the flag is set to '0'.

Any insights would be helpful.

Here's my subroutine.
B4X:
Sub refresh_check
Log(refreshtimer * 1000)   ' currently set to 10 (seconds)
    Do While 1 = 1
        Log("tick")
        Sleep(refreshtimer * 1000) '60000 = 1 min
        

            Dim req As DBRequestManager = CreateRequest
            Dim cmd As DBCommand = CreateCommand("check_refresh", Array(prepid, jdgnumber))
            Wait For (req.ExecuteQuery(cmd, 0, Null)) JobDone(j As HttpJob)
            If j.Success Then
                req.HandleJobAsync(j, "req")
                Wait For (req) req_Result(res As DBResult)
                Dim row() As Object = res.Rows.Get(0)
                
                If row(0) = 1 Then
                 Log("do refresh")
                 Refresh_Click    
                End If
            End If 
            j.release
                    
    Loop
End Sub
 

AKJammer

Active Member
Licensed User
I really know nothing about this, but using my "trial and error" method of working with B4X I'd try:

B4X:
If row(0) = "1" Then

or

B4X:
If 1 = row(0) Then
Oh Man!! That was it!!

if 1 = row(0)

I remember seeing something a couple years ago that Erel said to put the constant first. This is the first time that was an issue.

Thanks!!
 
Upvote 0

AKJammer

Active Member
Licensed User
This is something I don't understand well and it seems rather convoluted to me:
B4X:
Sub refresh_check
Log(refreshtimer * 1000)   ' currently set to 10 (seconds)
    Do While 1 = 1
        Log("tick")
        Sleep(refreshtimer * 1000) '60000 = 1 min
You want to call that Sub every 10 seconds but then inside the loop you make it take a 60 second pause; why?
Note that Sleep returns the flow to the caller.
That was the code before I found the timer object, I was making my own. One statement is a Log, the other is a sleep. The comments are just that. '60000 = 1 min
 
Upvote 0
Top