Android Question Problem. Activity Start from wrong place

hibrid0

Active Member
Licensed User
I have a function like this, my app connect to an internal API, but the is protected by VPN then is not avalaible on everytime.

My problem come from there, if the user try to download data from API but don't have VPN connected or no internet the httpJob persist on background, the user continue working on other activities.

But when the httpjob release by timeout, the activty source of the request bring to the front.
If the user touch the button download 10 times, are 10 timeouts, 10 bring to the front.
The app not crash and not blocked, but is no very nice for the user, if you are making something and bring other activities without any aparent reason.


I have 1 layout per activity, something like this:

Activity = act_report
Layout = frm_report


B4X:
Sub func_downloadsomething
    Dim Servidor As String
    Dim Puerto As String
    Servidor = "192.168.0.50"
    Puerto = "8888"
    Dim j As HttpJob
    j.Initialize("", Me)
    j.Download($"http://${Servidor}:${Puerto}/api/somedata"$)
    Log("Conexiión a Equipo remoto")
    Log($"http://${Servidor}:${Puerto}/api/somedata"$)
    Wait For (j) JobDone(j As HttpJob)
    If j.Success Then
        'Download something
        Dim parser As JSONParser
        parser.Initialize(j.GetString)
        Dim root As List = parser.NextArray
        For Each colroot As Map In root
            HOUR_START = colroot.Get("HOUR_START")
            ID = colroot.Get("ID")
            DATE1 = colroot.Get("DATE1")
            lista.FastScrollEnabled=True
            lista.AddTwoLines(ID, "Fecha: "&DATE1.SubString2(0, 10)&" Hora: "&HOUR_START)
        Next
    End If
    j.Release
End Sub
 
Top