Android Question Application crash to save in Firebase RealTime (in Release mode and but not Debug)

desof

Well-Known Member
Licensed User
Longtime User
Hello friends,

After a long time of insisting and insisting I have my app that is authenticated correctly in Firebase and it brings a record and it shows in a label, until there everything perfect even having the movil in the left hand I modify a value in Firebase from the computer and it is Reflects correctly in no more than 2 seconds.
Now my problem is that when I modify a value (attached code) in Firebase I get an unexpected closing of the app, and if I am in Debug mode I can not detect any errors.
It is important to clarify that the data is written correctly in Firebase in any way but I can not detect or less intercept the error.

Help me please


B4X:
Sub Process_Globals
    Dim ref As DatabaseReference 
End Sub

Sub Globals
    Dim realtime As FirebaseDatabase
    Private lbTittle As Label
    Private DSFloatingActionButton1 As DSFloatingActionButton
End Sub

Sub Activity_Create(FirstTime As Boolean)     
    Activity.LoadLayout("PostMain2") 
    '
    realtime.Initialize("Realtime") 
    realtime.PersistenceEnabled = True 
    realtime.goOnline 
    '
    ref.Initialize("Reference",realtime.getReferencefromUrl("https://myengineapp.firebaseio.com/")) 
    ref.addChildEventListener 
    ref.addListenerForSingleValueEvent 
    ref.addValueEventListener

End Sub

Sub Activity_KeyPress(KeyCode As Int) As Boolean
    If KeyCode = KeyCodes.KEYCODE_BACK Then
        'SALIR
        Activity.Finish
    Else If KeyCode = KeyCodes.KEYCODE_MENU Then
        'nothing
        '        WebView1.Visible=False

    Else
        Return True   ' con esto vuelves al programa, si no pones nada sale de el
    End If
End Sub
Sub Activity_Resume
    'Testfunction_updateChildren
End Sub
Sub Activity_Pause (UserClosed As Boolean)

End Sub
Sub Reference_onComplete(errorCode As Int, errorMessage As String, errObj As Object)
    Log($"Reference_onComplete(${errorCode},${errorMessage})"$)
    If errObj <> Null Then
        Dim err As DatabaseError = errObj
        Log($"  err.Code   =${err.Code}"$)
        Log($"  err.Details=${err.Details}"$)
        Log($"  err.Message=${err.Message}"$)
    End If
    If ref <> Null Then
        Dim ref As DatabaseReference = ref
        Log($"  ref.Key=${ref.Key}"$)
    End If

End Sub
Sub Reference_onCancelled(errnum As Int,error As String)
    Try
        Log($"ref_onCancelled(${errnum},${error})"$)
    Catch
        Log(LastException)
    End Try
 
End Sub
Sub Reference_onChildAdded(snapshot As Object, child As String)     
    Try
        'If child="TITAN" Then
            'lbTittle.TEXT=snapshot
            showSnapshot(snapshot)
        'End If
 
    Catch
        Log(LastException)
    End Try

 
    Log($"ref_onChildAdded(${child})"$)
End Sub
Sub Reference_onChildChanged(snapshot As Object, child As String)
    Try 
        showSnapshot(snapshot)
    Catch
        Log(LastException)
    End Try
End Sub
Sub Reference_onChildMoved(snapshot As Object, child As String)
    Try         
        showSnapshot(snapshot)
    Catch
        Log(LastException)
    End Try
End Sub
Sub Reference_onChildRemoved(snapshot As Object)
    Try
        Log($"ref_onChildRemoved()"$)
        showSnapshot(snapshot) 
    Catch
        Log(LastException)
    End Try

End Sub
Sub Reference_onDataChange(snapshot As Object)
    Try
        Dim snap As DataSnapshot = snapshot
        'Log("    Value="&snap.Value)
        Dim x As String = snap.Value
        If x.Length > 0 Then
            x = x.SubString2(0, Min(32, x.Length -1)) & "..."
        End If
        Log("#-  Value=" & x)
    Catch
        Log("#-  ERROR..." & CRLF & LastException.Message)
     
    End Try
End Sub
Sub showSnapshot(snapX As DataSnapshot)
    Try
        Dim snap As DataSnapshot = snapX
        Log("#-Snapshot:" & CRLF & snap.Value & CRLF )
        lbTittle.TEXT=snap.Value
    Catch
        Log(LastException)
    End Try     
End Sub

'AGREGAR A FIREBASE
Sub DSFloatingActionButton1_Click
    writeNewPost("24","5,2,9,6,4,21","21")
End Sub

Sub writeNewPost(salidas As String, Lista As String, Ultima As String) As Boolean
    '
    Dim tempref As DatabaseReference = ref.Child("TITAN") ' <--Un nodo que queremos escribir los datos a
    Dim posts As DatabaseReference = tempref.push         ' <-- Sólo necesitábamos esta referencia para obtener la clave autogenerada
    Dim key As String = posts.Key
    Log("#-  key=" & key)

    Dim mapPostValues As Map
    mapPostValues.Initialize
    mapPostValues.Put("Lista", Lista)
    mapPostValues.Put("Salidas", salidas)
    mapPostValues.Put("Ultima", Ultima)

    ' "Fanout" the data to different paths (NoSQL recommendation for up to 1 million simultaneous users)  --> https://firebase.googleblog.com/2015/10/client-side-fan-out-for-data-consistency_73.html
    Dim strUk1 As String = "/TITAN/2017/MAYO/Sorteo 2/"
'    Dim strUk2 As String = "/TITAN/2017/MAYO/Sorteo 1/Ultima/"
    Log("#-  strUk1=" & strUk1)
'    Log("#-  strUk2=" & strUk2)
 
    Try
        Dim childUpdates As Map
        childUpdates.Initialize
        childUpdates.Put(strUk1, mapPostValues)
        'childUpdates.Put(strUk2, mapPostValues)
        ref.updateChildren(childUpdates)      ' <-- This is the "atomic" update. ONE start of transaction no matter how many elements the map has
 
    Catch
        Msgbox(LastException,"")
    End Try
 
    Return True
 
End Sub
 

DonManfred

Expert
Licensed User
Longtime User
The FB Realtime Database library is not working as expected. Development has stopped. This is the reason why it is in the old libraries archieve.
I suggest not to use it anymore.
 
Upvote 0

desof

Well-Known Member
Licensed User
Longtime User
The FB Realtime Database library is not working as expected. Development has stopped. This is the reason why it is in the old libraries archieve.
I suggest not to use it anymore.
Hello @manfred

Thank you very much for your support.
I must say that the error was produced by calling the WitreNewPost Function unduly as I called it as follows
B4X:
Sub DSFloatingActionButton1_Click
    writeNewPost("24","75","21")
End Sub

And when you call it as it should be

B4X:
Sub DSFloatingActionButton1_Click
    If writeNewPost("24","75","21") Then
        Msgbox ("Correcto","")
    Else
        Msgbox ("FALLO","")
    End If
End Sub
The error was solved.
This error seems to me to have to do with B4A and although it is not logical to call a function the way I did it I think this should not happen.

And thanks for your advice not to use it anymore and it's a shame that it is not improved,
 
Upvote 0

DonManfred

Expert
Licensed User
Longtime User
and it's a shame that it is not improved
You are on the best way to get on my ignorelist.
I DONT CARE about that YOU think it is a shame.

I spent DAYS(!!) to develop the library. Sadfully i did not get it to work correctly.
I decided to stop the dev then.

Feel free to write your own wrap for the FB RT DB
 
Upvote 0
Top