Firebase Realtimedatabase

Status
Not open for further replies.

DonManfred

Expert
Licensed User
Longtime User
The database is loosing it´s instance values when getting references from itself.
As time of written this i dont recomment to use the library at all.
It is not reliable, incomplete.
 

desof

Well-Known Member
Licensed User
Longtime User
I get an application close in this line when I press the next button ??
B4X:
ref.Initialize("Reference", Starter.realtime.getReferencefromUrl($"https://${Starter.strFirebaseProjectId}.firebaseio.com/"$) )
 

desof

Well-Known Member
Licensed User
Longtime User
Hello,

Help please, why does the following line produce me error?
B4X:
ref.Initialize("Reference", Starter.realtime.getReferencefromUrl($"https://${Starter.strFirebaseProjectId}.firebaseio.com/"$) )

This is the error returned
QUOTE]
Error occurred on line: 95 (PostsMain)
com.google.firebase.database.DatabaseException: Invalid URL (https://fir-auth-b0829.firebaseio.com/) passed to getReference(). URL was expected to match configured Database URL: https://fir-quickstartsforandroi-93d9a.firebaseio.com
at com.google.firebase.database.FirebaseDatabase.getReferenceFromUrl(Unknown Source)
at de.donmanfred.FirebaseDatabaseWrapper.getReferencefromUrl(FirebaseDatabaseWrapper.java:115)
at java.lang.reflect.Method.invoke(Native Method)
at anywheresoftware.b4a.shell.Shell.runMethod(Shell.java:710)
at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:339)
at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:249)
at java.lang.reflect.Method.invoke(Native Method)
at anywheresoftware.b4a.ShellBA.raiseEvent2(ShellBA.java:134)
at anywheresoftware.b4a.BA$2.run(BA.java:338)
at android.os.Handler.handleCallback(Handler.java:746)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:148)
at android.app.ActivityThread.main(ActivityThread.java:5443)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:728)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:618)

[/QUOTE]
 

tigrot

Well-Known Member
Licensed User
Longtime User
Hi everybody,
I have a small test app in which I test read and write to a firebase DB. I'm building a class, in which I have a DbRead and DbWrite.
Read is OK, write works well, but the on_Completed is never called. If I dont' code the sub in class there is no error, but if I do i get this Error:
B4X:
java.lang.NullPointerException
    at de.donmanfred.DatabaseReferenceWrapper$5.onComplete(DatabaseReferenceWrapper.java:236)
    at com.google.android.gms.internal.zzbpj$20.run(Unknown Source)
    at android.os.Handler.handleCallback(Handler.java:725)
    at android.os.Handler.dispatchMessage(Handler.java:92)
    at android.os.Looper.loop(Looper.java:176)
    at android.app.ActivityThread.main(ActivityThread.java:5319)
    at java.lang.reflect.Method.invokeNative(Native Method)
    at java.lang.reflect.Method.invoke(Method.java:511)
    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1102)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:869)
    at dalvik.system.NativeStart.main(Native Method)
My code works well in a activity, but in a class it fails.
My class:
B4X:
Sub Class_Globals
    Dim reference As String
    Dim disc As Boolean
    Dim realtime As FirebaseDatabase
    Dim ref As DatabaseReference
    Dim father As Object
   
End Sub

'Initializes the object. You can add parameters to this method if needed.
Public Sub Initialize(refname As String,  disconnecteverytimetime As Boolean, activityname As Object)
   reference=refname
   disc=disconnecteverytimetime
   father=activityname
End Sub

Sub connectDB
    If realtime.IsInitialized= False Then
        realtime.Initialize("Realtime")
        realtime.PersistenceEnabled = True
    End If
    realtime.goOnline
End Sub

Sub writeDB(telefono As String, valore As String)
    connectDB
    ref.Initialize("Reference",realtime.getReferencefromUrl("https://<my-app>/users" ))
    Dim mp As Map
    mp.Initialize
    Dim mp1 As Map
    mp1.Initialize
    mp1.Put("IID",valore)
    mp.Put(telefono,mp1)
    ref.push
    ref.updateChildren(mp)
End Sub

Sub readDB(telefono As String)
    connectDB
    ref.Initialize("Reference",realtime.getReferencefromUrl("https://<my-app>/users/" & telefono))
    ref.addListenerForSingleValueEvent
End Sub

Sub Reference_oncomplete(errorCode As Int, errorMessage As String, errObj As Object)
    Log(errorMessage)
   
    CallSub3(father,reference & "_onComplete",errorCode,errorMessage)
    'If disc Then realtime.goOffline
End Sub

Sub Reference_onCancelled(errnum As Int,error As String)
    Log($"ref_onCancelled(${errnum},${error})"$)
End Sub
Sub Reference_onChildAdded(snapshot As Object, child As String)
    Log($"ref_onChildAdded(${child})"$)
End Sub
Sub Reference_onChildChanged(snapshot As Object, child As String)
    Log($"ref_onChildchanged(${child})"$)
End Sub
Sub Reference_onChildMoved(snapshot As Object, child As String)
    Log($"ref_onChildMoved(${child})"$)
End Sub
Sub Reference_onChildRemoved(snapshot As Object)
    Log($"ref_onChildRemoved()"$)
End Sub

Sub Reference_onDataChange(snapshot As Object)
        Log($"ref_onDatachange()"$)
    Dim snap As DataSnapshot = snapshot
    If snap.exists = False Then
        Dim mapnul As Map
        mapnul.initialize
        If disc Then realtime.goOffline
       
        CallSub2(father,reference & "_onDataChange", mapnul)
        Return
    End If

    Dim json As JSONParser
    json.Initialize(snap.Value)
    Dim root As Map = json.NextObject
    If disc Then realtime.goOffline
    CallSub2(father,reference & "_onDataChange", root)
End Sub
 

Widget

Well-Known Member
Licensed User
Longtime User
The library is not maintained anymore as it was a total fail, does not work as expected (that´s the reason why the lib is listed in the "old library archive")

I suggest not to use it anymore.

Don, maybe when a library is not "production quality", the first line of the first post should say something like (on bold red text):
"Library has been discontinued and is no longer supported. It is posted for educational purposes only.
Library is not recommended for production applications due to too many errors.
Library has been replaced by libraryxyz".

That way people know right away whether it is usable without reading through the thread. It is still posted because people can still learn from it.
Just a thought.
 

DonManfred

Expert
Licensed User
Longtime User
The library is not search-able as it is placed in this sub-forum.
I now removed the link in my Libraryoverview too.

Don, maybe when a library is not "production quality", the first line of the first post should say something like (on bold red text)
Feel free to do this on all libraries you wrote.
 

tigrot

Well-Known Member
Licensed User
Longtime User
Hi Don,
the library works for me, I have only this issue, which I'll try to fix by myself.
Is java_src120-zip the last source?
I think the on_complete error.message is not handled correctly. When you get no error in writing, it's NULL and that is the error I get.
I have a little experience in wrapping, but I have seen that it basically converts call from B4A to Firebase DB with a few added code.
Ciao
Mauro
 

Widget

Well-Known Member
Licensed User
Longtime User
The library is not search-able as it is placed in this sub-forum.
I now removed the link in my Libraryoverview too.


Feel free to do this on all libraries you wrote.

I'm sorry if I offended you Don. It certainly wasn't my intent. I appreciate all the work you've done here.

My comment was to notify any newbie as to why any particular library (not just yours) is discontinued so they know right off on the very first post (without reading through the entire thread which many people don't do) if the library could still be used in a production environment.
 

desof

Well-Known Member
Licensed User
Longtime User
HELLO,

I am trying to connect to my Base in real time and I get this error and I can not move forward.
What is the problem please if you help me.
This is the sample that I download and I'm trying
thank you very much !

Logger connected to: motorola XT890
--------- beginning of /dev/log/main
*** Service (starter) Create ***
** Service (starter) Start **
** Activity (main) Create, isFirst = true **
lib:Raising.. reference_oncancelled()
lib:Raising.. reference_oncancelled()
lib:Raising.. reference_oncancelled()
ref imagesizes = https://esquefengineapp.firebaseio.com/imagesizes
** Activity (main) Resume **
An error occurred:
(Line: 47) End Sub
java.lang.Exception: Sub reference_oncancelled signature does not match expected signature.
public static anywheresoftware.b4a.pc.RemoteObject sancrisapp.dos.cero.main_subs_0._reference_oncancelled(anywheresoftware.b4a.pc.RemoteObject,anywheresoftware.b4a.pc.RemoteObject) throws java.lang.Exception

*** Service (starter) Create ***
** Service (starter) Start **
** Activity (main) Create, isFirst = true **
lib:Raising.. reference_oncancelled()
lib:Raising.. reference_oncancelled()
lib:Raising.. reference_oncancelled()
ref imagesizes = https://esquefengineapp.firebaseio.com/imagesizes
** Activity (main) Resume **
An error occurred:
(Line: 47) End Sub
java.lang.Exception: Sub reference_oncancelled signature does not match expected signature.
public static anywheresoftware.b4a.pc.RemoteObject sancrisapp.dos.cero.main_subs_0._reference_oncancelled(anywheresoftware.b4a.pc.RemoteObject,anywheresoftware.b4a.pc.RemoteObject) throws java.lang.Exception

*** Service (starter) Create ***
** Service (starter) Start **
** Activity (main) Create, isFirst = true **
lib:Raising.. reference_oncancelled()
lib:Raising.. reference_oncancelled()
lib:Raising.. reference_oncancelled()
ref imagesizes = https://esquefengineapp.firebaseio.com/imagesizes
** Activity (main) Resume **
An error occurred:
(Line: 47) End Sub
java.lang.Exception: Sub reference_oncancelled signature does not match expected signature.
public static anywheresoftware.b4a.pc.RemoteObject sancrisapp.dos.cero.main_subs_0._reference_oncancelled(anywheresoftware.b4a.pc.RemoteObject,anywheresoftware.b4a.pc.RemoteObject) throws java.lang.Exception
 

DonManfred

Expert
Licensed User
Longtime User
I spent some time on the RTDB (again!) as i have some time and the FirebaseFirestore is still in Beta... I started a wrap on this but i can release it only after the Firestore is part of the Google Playservices.... So i have to wait.
I updated the RTDB to use the newest Playservice....

I now have a working version which is able to read data from a specific path (was true in the past). Based on the info that the realtimedatabase is ONE BIG Tree you´ll fetch a lot of data if you request for example a list of all your customers....
That´s ok but if the customer itself contains a lot of "sub-data" then all this sub-data will be reuqested too. This may lead in a huge Traffic.

The point is that it is adviced to have the RTDB as flat as possible to prevent such big data-requests.

Basically it is this code to get all Customers (stored in the Tree /customers/). In this case i only want to get the first 5 of them.

B4X:
    ' Get a reference to the customers folder of the DB. Do not set any Listeners here....
    cust.Initialize("Customers",realtime.getReference2("customers/"),"customers/")
    ' Now we create a query from the cust-reference and get the first 5 Items (including all subtree-data from them)
    ' The last we add is the Listener
    Dim qry As Query = cust.LimitToFirst(5).orderByChild("id").setEventname("Customers","customers").addChildEventListener.addValueEventListener

Logger verbunden mit: 9885e6514556383552
--------- beginning of crash
--------- beginning of main
--------- beginning of system
*** Service (starter) Create ***
** Service (starter) Start **
** Activity (main) Create, isFirst = true **
** Activity (main) Resume **
*** Service (firebasemessaging) Create ***
** Service (firebasemessaging) Start **
lib:Raising.. customers_onchildadded()
lib:Raising.. customers_onchildadded()
lib:Raising.. customers_onchildadded()
lib:Raising.. customers_onchildadded()
lib:Raising.. customers_onchildadded()
ref_onChildAdded(customers,root)
libquery:Raising.. customers_ondatachange()
NOTE: The addChildEventListener is responsible for these Events....
customers_onChildAdded(8,customers, SizeofCustomers: 1)
customers_onChildAdded(9,customers, SizeofCustomers: 2)
customers_onChildAdded(10,customers, SizeofCustomers: 3)
customers_onChildAdded(11,customers, SizeofCustomers: 4)
customers_onChildAdded(12,customers, SizeofCustomers: 5)
NOTE: The addValueEventListener is resposible for this Event.
customers_onDatachange(customers)
Note: you´ll get a list of Maps with the 5 results (in this case)
So, basically you only need either the addValueEvenentListener OR the addChildEventListener

** Activity (main) Pause, UserClosed = false **
** Activity (main) Resume **

WhatsApp Image 2017-11-02 at 08.52.39.jpeg


Work in Progress!
 
Last edited:

DonManfred

Expert
Licensed User
Longtime User
Another example. It reads the content of
B4X:
"users/"&Starter.phone.GetSettings("android_id")&"/Messages"

B4X:
    mymessages.Initialize("Chat",realtime.getReference2("users/"&Starter.phone.GetSettings("android_id")&"/Messages"),"users/"&Starter.phone.GetSettings("android_id")&"/Messages")
    mymessages.LimitToFirst(5).addChildEventListener

*** Service (starter) Create ***
** Service (starter) Start **
** Activity (main) Create, isFirst = true **
** Activity (main) Resume **
*** Service (firebasemessaging) Create ***
** Service (firebasemessaging) Start **
lib:Raising.. chat_onchildadded()
lib:Raising.. chat_onchildadded()
lib:Raising.. chat_onchildadded()
lib:Raising.. chat_onchildadded()
lib:Raising.. chat_onchildadded()
ref_onChildAdded(customers,root)
chat_onChildAdded(-Kxr8Itwnotrgdcj1hux,users/b0d0d7f9b81140c3/Messages)
(MyMap) {time=1509532450428, From=ErelClone, Message=Hiiii Master, Title=MyGreatSubject}
chat_onChildAdded(-Kxr8n0dyaX-xhBZ465A,users/b0d0d7f9b81140c3/Messages)
(MyMap) {time=1509532577897, From=ErelClone, Message=Hello there, Title=this is the subject}
chat_onChildAdded(-Kxr9xkvk_gLGDDMgvGQ,users/b0d0d7f9b81140c3/Messages)
(MyMap) {time=1509532884028, From=AnotherUser, Message=You are great, Title=My subject}
chat_onChildAdded(-KxrC8Pg8bvQLwtRwEyW,users/b0d0d7f9b81140c3/Messages)
(MyMap) {time=1509533456045, From=AnotherUser, Message=Hello there, Title=My subject}
chat_onChildAdded(-KxrIdKfXuD9SmxrRPAQ,users/b0d0d7f9b81140c3/Messages)
(MyMap) {time=1509535159660, From=Someone, Message=Hi Master, Title=this is the subject}
** Activity (main) Pause, UserClosed = false **
** Activity (main) Resume **
 

Alexander Stolte

Expert
Licensed User
Longtime User
Which imports do I have to add?

i have this error on compile:

B4X:
Objects\bin\extra\res7\res\values-v26\values-v26.xml:16: error: Error: No resource found that matches the given name: attr 'android:autofillHints'.
 
Status
Not open for further replies.
Top