Android Question FOR (Loop) and Call a WebService | OkHttpUtils2

Discussion in 'Android Questions' started by trejocode, Jun 17, 2019.

  1. trejocode

    trejocode Member Licensed User

    Hello, I have a problem is that I do not understand at all how to "Block" an HTTP request because I use Wait For (Resumable).
    Look at the case:

    I select my items from my local database, and then I send the data to an API but they are not sent properly because, as it is a "non-blocking" event, it overwrites the "current" values by the last one, I attach an example of what I have:

    Code:
    Sub FirstStep
        
    'Get Data from SQLite
        SQL.BeginTransaction
        
    Try
            
    Cursor = SQL.ExecQuery("SELECT column1, column1 FROM table WHERE something = 0")
            
    For i = 0 To Cursor.RowCount -1
                
    Cursor.Position = i
                
    Dim Column1 As String = Cursor.GetInt("column1")
                
    Dim Column2 As String = Cursor.GetInt("column2")
                SendData(Column1, Column2)
            
    Next
            
    SQL.TransactionSuccessful
        
    Catch
            
    Log(LastException.Message)
        
    End Try
        
    SQL.EndTransaction
        
        
    End Sub

    Sub SendData(Column1 As Int, Column2 As Int)
        
        
    Dim Data As Map
        Data.Initialize
        Data.Put(
    "data1", Column1)
        Data.Put(
    "data2", Column2)
        
    Dim JSONGenerator As JSONGenerator
        
    JSONGenerator.Initialize(Data)
        
    Dim JSONString As String
        JSONString = 
    JSONGenerator.ToString
        HTTP.PostString(
    "http://"&IP&":8081/petition", JSONString)
        HTTP.GetRequest.SetContentType(
    "application/json")
        HTTP.GetRequest.Timeout = 
    30000
        
    Wait For (HTTP) JobDone(response As HttpJob)
        
    If response.Success Then
            
    Dim Successful As Boolean = response.Success
            
    ' If the Data are Inserted on the WebService THEN: UPDATE MY SQLite DB
            If Successful Then
                
    SQL.BeginTransaction
                
    Try
                    
    SQL.ExecNonQuery2("UPDATE table SET status = 1 WHERE something = ?"Array As Object(Column1))
                    
    SQL.TransactionSuccessful
                
    Catch
                    
    Log(LastException.Message)
                
    End Try
                
    SQL.EndTransaction
            
    Else
                
    Log("Nope, ERROR")
            
    End If
        
    End If
        HTTP.Release
        
    End Sub
    What I would like is to find the way to do "Blocking the HTTP JOB" the event of sending to the API so that everything is inserted properly and not only insert the last one, or what would be the way to make it send the data of proper way?

    Thank you
     
    Last edited: Jun 18, 2019
  2. trejocode

    trejocode Member Licensed User

    I can't :(
     
  3. DonManfred

    DonManfred Expert Licensed User

Loading...
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice