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
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