Android Question Firebase Storage - Never times out

Robert Valentino

Well-Known Member
Licensed User
Longtime User
If you don't have a internet connection doing a Firebase Storage DownloadStream will never time out, program just hangs on waiting for it.

I guess I need to start checking for if connected to internet before all these things.
Live in real remote area and sometimes cell service just goes away. I know hard to believe in 2021 with the rest of the world going 5G
 

Erel

B4X founder
Staff member
Licensed User
Longtime User
program just hangs on waiting for it.
The program will never hang. The event will not be raised.

You can implement the timeout with this code:
B4X:
    Starter.storage.DownloadFile("/public/Untitled.png", File.DirInternal, "1.txt")
    Dim stop() As Boolean = Array As Boolean(False)
    MonitorDownload(stop)
    Wait For Storage_DownloadCompleted (ServerPath As String, Success As Boolean)
    stop(0) = True
    If Success Then
        Log("download successfully")
    End If

Sub MonitorDownload(stop() As Boolean)
    Dim Start As Long = DateTime.now
    Dim Timeout As Long = 10 * DateTime.TicksPerSecond
    Do While stop(0) = False And Start + Timeout > DateTime.Now
        Sleep(200)
    Loop
    If stop(0) = False Then
        Log("Timeout")
        CallSubDelayed3(Me, "Storage_DownloadCompleted", "", False)
    End If
End Sub
 
Upvote 0

Robert Valentino

Well-Known Member
Licensed User
Longtime User
I finally got around to actually verifying that this works (only effects me when there is no internet).

The timeout happens (see the log message) but the code never returns to the statement after the wait for.

Noticed you have your storage in Starter, this is a B4X project and Storage is in one of my pages - don't think that matters
 
Upvote 0

Robert Valentino

Well-Known Member
Licensed User
Longtime User
I have a monitor download I use for a stream that works fine.

So I called this routine monitor_download, I'm sure the name in this case is unrelated.

I have a few places in my code where I am doing a wait for Storage_DownloadCompleted.

I'm confused on how the callsub knows where to return to. I'm sure it's just on the stack. But for me confusing

Sorry for no code tagging doing this on my phone
 
Upvote 0

agraham

Expert
Licensed User
Longtime User
Upvote 0

Robert Valentino

Well-Known Member
Licensed User
Longtime User
I went to eat lunch and when I returned the wait had returned. But it surely took a long time after the timeout happened.

It actually seems like it happen when the device screen when to sleep

Going to see if I can create a little test program
 
Upvote 0

Robert Valentino

Well-Known Member
Licensed User
Longtime User
OK, it does timeout
B4X:
Time Before Download:13:10:33
TimeOut:13:10:43
Time After Download:13:16:59

The Time message Before Download is when I do the Wait for download
The TimeOut message is when the Monitor Routine timer is hit and calls the Storage_DownloadCompleted
The last After Download is when the program returns. I is almost a full 6 minutes after the callsubdelayed happened.

B4X:
Dim stop() As Boolean = Array As Boolean(False)
Monitor_Download(stop)    

Log("Time Before Download:" &DateTime.Time(DateTime.Now))

                    Wait For (storage) Storage_DownloadCompleted(ServerPath As String, Success As Boolean)
    
stop(0) = True    
Log("Time After Download:" &DateTime.Time(DateTime.Now))

Monitor_Download routine
B4X:
Sub Monitor_Download(stop() As Boolean)
    Dim Start As Long = DateTime.now
    Dim Timeout As Long = 10 * DateTime.TicksPerSecond
    Do While stop(0) = False And Start + Timeout > DateTime.Now
        Sleep(200)
    Loop
    If stop(0) = False Then
        Log("TimeOut:" &DateTime.Time(DateTime.Now))
        
        CallSubDelayed3(Me, "Storage_DownloadCompleted", "", False)
    End If
End Sub
 
Upvote 0

Robert Valentino

Well-Known Member
Licensed User
Longtime User
Tried to create an example, but my wifi is out and I can't easily get to firebase to add a project to create a Jason file.

Maybe next week if wifi returns
 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…