Android Question Read data from a url

bixmatech

Member
Licensed User
Upvote 0

bixmatech

Member
Licensed User
my problem is that i want the checkinternet function to finish completely and update the variable ConnexioInternet before the if ConnexioInternet statement execute, got me?
 
Upvote 0

bixmatech

Member
Licensed User
Do you mean modifying it like this? if yes it didnt work
B4X:
Sub Globals
    'These global variables will be redeclared each time the activity is created.
    'These variables can only be accessed from this module.
    Dim ConnexioInternet As String
    Dim no_intenet As String = "<center><h1>No Internet</h1></center>"
End Sub

Sub Activity_Create(FirstTime As Boolean)
    'Do not forget to load the layout file created with the visual designer. For example:
    'Activity.LoadLayout("Layout1")
  
    Dim myw As WebView
    myw.Initialize("myw")
    Activity.AddView(myw, 0, 0, 100%x, 100%y) 'Your options for size here
    Log("Will check internet now")
    CheckInternet
    If ConnexioInternet = "value is 5" Then
        Log("Internet: 1")
        myw.LoadUrl("http://www.stackoverflow.com")
    Else
        Log("Internet: 0")
        myw.LoadUrl($"no_internet"$)
    End If
End Sub

Sub CheckInternet
    Dim j As HttpJob
    j.Initialize("JobA", Me)
    j.Download("http://bixma.com/test_value.txt")
    Wait For (j) JobDone(j As HttpJob)
   
    Select j.JobName
        Case "JobA"
            If j.Success Then
                ConnexioInternet = j.GetString
                Log(ConnexioInternet)
            End If
    End Select
   
    j.Release
End Sub
 
Upvote 0

OliverA

Expert
Licensed User
Longtime User
Don't use a separate sub
B4X:
Sub Activity_Create(FirstTime As Boolean)
    'Do not forget to load the layout file created with the visual designer. For example:
    'Activity.LoadLayout("Layout1")
  
    Dim myw As WebView
    myw.Initialize("myw")
    Activity.AddView(myw, 0, 0, 100%x, 100%y) 'Your options for size here
    Log("Will check internet now")
    Dim j As HttpJob
    j.Initialize("", Me)
    j.Download("http://bixma.com/test_value.txt")
    Wait For (j) JobDone(j As HttpJob)
    If j.Success Then
        ConnexioInternet = j.GetString
        Log(ConnexioInternet)
    End If
    j.Release
    If ConnexioInternet = "value is 5" Then
        Log("Internet: 1")
        myw.LoadUrl("http://www.stackoverflow.com")
    Else
        Log("Internet: 0")
        myw.LoadUrl($"no_internet"$)
    End If
End Sub
 
Upvote 0

bixmatech

Member
Licensed User
This is not logical, as if i have 100 buttons in the app and i want to check internet , then i have to write the code 100 time. lol
 
Upvote 0
Top