I have been using the above code for some time to access txt files and a database on a hosted website.
Erel's original reference was:
Downloading resources is simpler with the new Resumable Subs feature. Using Wait For we can wait for the JobDone event in the same sub that started the download. No longer is it needed to have a single sub that handles all requests results. Simplest example: Dim j As HttpJob j.Initialize(""...
At one point, something motivated me to question what would happen if I could not access the internet. I tested using 'airplane' mode and found that the logic falls through and the 'j.download' does not appear to happen.
I have modified the above as shown for the simple case where the app is attempting to read from the internet.
Dim j As HttpJob
j.Initialize("", Me)
j.Download("https://www.google.com")
Wait For (j) JobDone(j As HttpJob)
If j.Success Then
Log(j.GetString)
else
ToastMessageShow("Unable to access the Internet at this time",False)
j.release
Return
End If
j.Release
' Continued logic if successful
There are a several other situations in which I have added additional logic in lieu of the 'toastmessage'.
1. Reading 'help' files. My latest help files are txt files on the website. I have added logic to access the help file from the app 'files' folder if the internet fetch fails. The local 'help' entry may or may not be current depending on whether I have put out a new version since the help update.
2. My version of 'push' notifications. I have a routine called from the initial 'Appear' of B4XMainPage in which I look to the website for a message. If it is the same date as the previous message it is ignored, if it is a new date, it is displayed on the bottom of the main menu. If the internet is not accessible, I don't give any message and 'return'.
3. Updating a hosted database. I have a 'Sync' application in which records updated on one device are sent to other users via a hosted website/database. The other users query this website/database periodically to get the latest records.
Sending device
a. Updates the device's own local table.
b. Writes a command line containing the command as well as the data to be updated on the other devices into a local table 'CommandLines'.
c. When the B4XMainPage 'appears' after returning from the update 'pages', a Starter sub is fired that loops through the 'CommandLines' table and sends each command line in turn. If the 'send' loop is successful, it then deletes the records in the 'CommandLines' table. If it fails, the logic 'returns' and the delete is never done. The loop will be attempted next time B4XMainPage 'appears'.
d. In this case the 'CommandLines' table is serving as a buffer. Lines can be added as needed before the loop is successful and the records sent and then deleted.
Receiving device
a similar routine is fired from B4XMainPage to query the remote database. If the Internet connection is not available, the logic 'Returns' and will be tried later. If the read is successful, the records are updated in the local tables and another query is fired to delete the 'hosted' records for this user.
4. If your database is not local and is only 'hosted', you could inform the user that their data is not accessible.