Android Question [solved] CloudKVS: handling extra callbacks?

Dave O

Well-Known Member
Licensed User
Longtime User
When using CloudKVS to make a multi-device/user app, I extended it (v1.1) to raise a NewData event with a list of changes, as covered in this code snippet.

Since then, I've modified the CloudKVS code (v1.2) so I can call refreshUser and always get a reply even if there are no changes. I've renamed the event from NewData to RefreshDone accordingly.

However, I'm now getting extra events raised (e.g. I call refreshUser and get 2 RefreshDone events raised). I'm not sure why. Here's the relevant code from the ClientKVS class, with just 2 changes ("new in 1.2").

Any help much appreciated!

ClientKVS:
Private Sub ser_BytesToObject (Success As Boolean, NewObject As Object)
    Dim ser As B4XSerializator = Sender
    Dim m As Map = ser.Tag
    If Success Then
        Dim items As List = NewObject
        If items.Size > 0 Then
            For Each itemInstance As item In items
                InsertItemIntoData(itemInstance, True)
                addItemUserKeyToChangeList(itemInstance)        'new in 1.1
            Next
            sql.ExecNonQueryBatch("getuser")                        'continues with GetUser_NonQueryComplete
        Else                                      'new in 1.2
            Dim tempList As List                'new in 1.1
            tempList.Initialize                'new in 1.1
            CallSub2(mCallback, mEventName & "_refreshdone", tempList)        'return empty list
        End If
    Else
        Log("Error reading server response")
    End If
    DeleteFromQueue(m.Get("queue_id"))
    HandleQueue
End Sub

Private Sub GetUser_NonQueryComplete (Success As Boolean)
    If Not(Success) Then
        Log("Error writing to database: " & LastException)
    End If
'    CallSub(mCallback, mEventName & "_newdata")
    Dim tempList As List                'new in 1.1
    tempList.Initialize                'new in 1.1
    tempList.AddAll(changeList)    'new in 1.1
'    CallSub2(mCallback, mEventName & "_newdata", tempList)            'new in 1.1
    CallSub2(mCallback, mEventName & "_refreshdone", tempList)        'new in 1.2
    changeList.Clear                    'new in 1.1
End Sub
 

Dave O

Well-Known Member
Licensed User
Longtime User
Finally discovered the problem: my CallSub2 to GetUser_NonQueryComplete should be a CallSubDelayed2, so that the item can be deleted from the queue before GetUser_NonQueryComplete runs.
 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…