Firebase Realtimedatabase

Status
Not open for further replies.

Alexander Stolte

Expert
Licensed User
Longtime User
A new version of the library has been released including the following and more:

B4X:
onDisconnectSetValue 'if you lost your conncection or the user is close the app, then you can set here a value, this is then set.
onDisconnectRemove 'the same, but only here is the value deleted.

And now a example for using:

B4X:
Sub Activity_Create(FirstTime As Boolean)

Dim typingref As DatabaseReference
Dim realtime As FirebaseDatabase
typingref.Initialize("istyping",realtime.getReference2("/rooms/" & "MyRoomId & "/typingIndicator"),"chats")
typingref.addChildEventListener

typingref.onDisconnectSetValue(CreateMap("MyIdOrColumn" : False)) 'if i disconnect or i lost my connection to the Database, then the Value set to false
'for example i write a text and then i lost my connection, then set the value to false and my chat partner know that i dont writing anymore, because i lost my connection.

typingref.goOnline

typingref.keepSynced(True)

End Sub
 

DonManfred

Expert
Licensed User
Longtime User

softmicro

Member
Licensed User
Longtime User
'Sorry For my English but I'm from Argentina and I speak Spanish.
'I Try To start tests with firebase And use FirebaseRealtimeDatabase And Try the examples of the foristas but I get errors just by adding the libraries of 'FirebaseRealtimeDatabase Or FirebaseUI without doing any program such As the example I am showing below.
'I can Not even start any of the examples because just adding FirebaseRealtimeDatabase gives errors that Do Not allow Me To finish the compilation. Can someone give Me the 'solution To this problem?
'Thank you And I will correspond To the one who gives Me the solution To use this library And the authentication by google And If possible by email And password.

Example for test

Sub Process_Globals
'These global variables will be declared once when the application starts.
'These variables can be accessed from all modules.

End Sub

Sub Globals
'These global variables will be redeclared each time the activity is created.
'These variables can only be accessed from this module.

End Sub

Sub Activity_Create(FirstTime As Boolean)
'Do not forget to load the layout file created with the visual designer. For example:
'Activity.LoadLayout("Layout1")
ToastMessageShow("Only test",False)
End Sub

Sub Activity_Resume

End Sub

Sub Activity_Pause (UserClosed As Boolean)

End Sub


'B4A Versión: 8.00'
'with only FirebaseRealtimeDatabase (Version: 2.53)
'[Generando el fichero R. Error
'C:\Users\softm\Downloads\PRUEBA\Ob'ects\bin\extra\res1\res\values\values.xml:118: error: Error retrieving parent For item: No resource found that matches the given name 'Theme.AppCompat.DayNight.DarkActionBar'.
'C:\Users\softm\Downloads\PRUEBA\Objects\bin\extra\res1\res\values\values.xml:121: error: Error: No resource found that matches the given name: attr 'colorAccent'.
'C:\Users\softm\Downloads\PRUEBA\Objects\bin\extra\res1\res\values\values.xml:119: error: Error: No resource found that matches the given name: attr 'colorPrimary'.
'C:\Users\softm\Downloads\PRUEBA\Objects\bin\extra\res1\res\values\values.xml:120: error: Error: No resource found that matches the given name: attr 'colorPrimaryDark'.
'C:\Users\softm\Downloads\PRUEBA\Objects\bin\extra\res1\res\values\values.xml:139: error: Error retrieving parent For item: No resource found that matches the given name '@style/Widget.AppCompat.Button.Colored'.
'C:\Users\softm\Downloads\PRUEBA\Objects\bin\extra\res1\res\values\values.xml:183: error: Error retrieving parent For item: No resource found that matches the given name '@style/Widget.AppCompat.Spinner.Underlined'.
'C:\Users\softm\Downloads\PRUEBA\Objects\bin\extra\res1\res\values\values.xml:284: error: Error retrieving parent For item: No resource found that matches the given name 'Widget.Design.TextInputLayout'.


'with only FirebaseUI (Version 0.22)
'B4A Versión: 8.00
'Generando el fichero R. Error
'C:\Users\softm\Downloads\PRUEBA\Objects\bin\extra\res1\res\values\values.xml:118: error: Error retrieving parent For item: No resource found that matches the given name ''Theme.AppCompat.DayNight.DarkActionBar'.
'C:\Users\softm\Downloads\PRUEBA\Objects\bin\extra\res1\res\values\values.xml:121: error: Error: No resource found that matches the given name: attr 'colorAccent'.
'C:\Users\softm\Downloads\PRUEBA\Objects\bin\extra\res1\res\values\values.xml:119: error: Error: No resource found that matches the given name: attr 'colorPrimary'.
'C:\Users\softm\Downloads\PRUEBA\Objects\bin\extra\res1\res\values\values.xml:120: error: Error: No resource found that matches the given name: attr 'colorPrimaryDark'.
'C:\Users\softm\Downloads\PRUEBA\Objects\bin\extra\res1\res\values\values.xml:139: error: Error retrieving parent For item: No resource found that matches the given name ''@style/Widget.AppCompat.Button.Colored'.
'C:\Users\softm\Downloads\PRUEBA\Objects\bin\extra\res1\res\values\values.xml:183: error: Error retrieving parent For item: No resource found that matches the given name ''@style/Widget.AppCompat.Spinner.Underlined'.
'C:\Users\softm\Downloads\PRUEBA\Objects\bin\extra\res1\res\values\values.xml:284: error: Error retrieving parent For item: No resource found that matches the given name ''Widget.Design.TextInputLayout'.
 

josejad

Expert
Licensed User
Longtime User
Hi Softmicro:

You should start a new thread for this issue.
Please, use code tags to show the code.
The problem seems to be related with Appcompat and the theme of the example, not with firebase libraries.

Hay un foro en español también en el que puedes intentar obtener ayuda si no se te da bien el inglés, aunque creo que tu post se entiende bastante bien.
 

DonManfred

Expert
Licensed User
Longtime User
Library updated. It now support sorting, limiting.

I put a new Example in #1. The Database is now used inside the Starter Service.

B4X:
Sub Process_Globals
    'These global variables will be declared once when the application starts.
    'These variables can be accessed from all modules.
    Dim realtime As FirebaseDatabase
    Dim msgref As DatabaseReference
    Public phone As Phone
End Sub

Sub Service_Create
    'This is the program entry point.
    'This is a good place to load resources that are not specific to a single activity.
End Sub
Sub Service_Start (StartingIntent As Intent)
    realtime.Initialize("Realtime")
    realtime.PersistenceEnabled = True
    realtime.goOnline
    ' I´m getting a reference to a specific sub-node of the Database. In this case /users/xxxxx/Messages
    ' Here i am storing Messages from this user. 
    msgref.Initialize("Reference",realtime.Reference.Child("users/"&phone.GetSettings("android_id")&"/Messages"),"users/"&phone.GetSettings("android_id")&"/Messages")

    Dim qry As FBQuery
    qry.Initialize("QueryResult",msgref.orderByChild("time").QueryObj) ' Order by
    qry.limitToFirst(3).addListenerForSingleValueEvent
End Sub

This is an example of my DB Layout

xclv_087.png


Messages contains >10 Entries. In the above Query i am sorting them by time and limit the output to the first three of them.

Logger connected to: 988ad036525346515630
--------- beginning of main
--------- beginning of system
*** Service (starter) Create ***
** Service (starter) Start **
** Activity (main) Create, isFirst = true **
** Activity (main) Resume **
lib1:Raising.. queryresult_ondatachange()
QueryResult_onDataChange()
{Message=You are great, Title=this is the subject, From=ErelClone, time=1546412882568}
{Message=Hi Master, Title=My subject, From=ErelClone, time=1546412818120}
{Message=Hi Master, Title=MyGreatSubject, From=AnotherUser, time=1546412641788}
** Activity (main) Pause, UserClosed = false **
** Activity (main) Resume **
 

rogersantosferreira

Member
Licensed User
Longtime User
Hello! How can I get a functional library example? Is it still being maintained or is there something official about B4x for integration with Firebase Realtime DB?

The example posted with the lib doesn't work for me!

B4X:
Error occurred on line: 74 (Starter)
java.lang.NullPointerException: Attempt to invoke virtual method 'java.lang.Class java.lang.Object.getClass()' on a null object reference
    at anywheresoftware.b4a.keywords.Common.GetType(Common.java:754)
    at com.b4atest.starter._queryresult_ondatachange(starter.java:217)
    at java.lang.reflect.Method.invoke(Native Method)
    at anywheresoftware.b4a.shell.Shell.runMethod(Shell.java:732)
    at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:348)
    at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:255)
    at java.lang.reflect.Method.invoke(Native Method)
    at anywheresoftware.b4a.ShellBA.raiseEvent2(ShellBA.java:144)
    at anywheresoftware.b4a.BA$2.run(BA.java:370)
    at android.os.Handler.handleCallback(Handler.java:873)
    at android.os.Handler.dispatchMessage(Handler.java:99)
    at android.os.Looper.loop(Looper.java:193)
    at android.app.ActivityThread.main(ActivityThread.java:6923)
    at java.lang.reflect.Method.invoke(Native Method)
    at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:870)

Thanks in advance!
 
Last edited:

DonManfred

Expert
Licensed User
Longtime User

DonManfred

Expert
Licensed User
Longtime User

imam syaifuddin

Member
Licensed User
Longtime User
I tried to compile and error

B4A Version: 9.80
Java Version: 11
Parsing code. (0.01s)
Building folders structure. (0.05s)
Compiling code. Error
Error compiling program.
Error description: ',' expected.
Error occurred on line: 40
ref.Initialize("Reference",realtime.getReferencefromUrl("https://fooddelivery-5f3bb.firebaseio.com"))
Word: )

B4X:
Sub Activity_Create(FirstTime As Boolean)
    'Do not forget to load the layout file created with the visual designer. For example:
    'Activity.LoadLayout("Layout1")
    realtime.Initialize("Realtime")
    realtime.PersistenceEnabled = True
    realtime.goOnline
   
    Dim ref As DatabaseReference
    ref.Initialize("Reference",realtime.getReferencefromUrl("https://fooddelivery-5f3bb.firebaseio.com"))
    ref.addChildEventListener
    ref.addListenerForSingleValueEvent
    ref.addValueEventListener
    Log("ref imagesizes = "&ref.Child("imagesizes"))
 
Last edited:

DonManfred

Expert
Licensed User
Longtime User
1. You should always create a new thread in the questionsforum for any Issue you have. Posting to existing threads is a mistake.
2. The error suggests that you forgot a , here. DatabaseReference needs three parameters. The Eventprefix, the reference to your db and an Tag object.
 

angkas4

New Member
1. You should always create a new thread in the questionsforum for any Issue you have. Posting to existing threads is a mistake.
2. The error suggests that you forgot a , here. DatabaseReference needs three parameters. The Eventprefix, the reference to your db and an Tag object.
but in example project , code writen in 2 parameter #85 , what the problem? or my
DatabaseReference not same with you use?
 
Hi
I am using this library and the example posted on one of B4A tutorial series on internet.
When i am compiling the the code i am getting error

Error log:
B4A Version: 10.70
Parsing code.    (0.02s)
    Java Version: 11
Building folders structure.    (0.01s)
Compiling code.    (0.03s)
Compiling layouts code.    (0.00s)
Organizing libraries.    (0.03s)
    (AndroidX SDK)
Compiling resources    (0.61s)
Linking resources    (0.47s)
Compiling generated Java code.    (3.29s)
Convert byte code - dex.    Error
Uncaught translation error: com.android.dx.cf.code.SimException: invalid opcode ba (invokedynamic requires --min-sdk-version >= 26)
1 error; aborting

Example is taken from


I followed forum mentioned solutions on same problem along with recommended package installation from SDK manager but still not able to succeed
Please help me to get out of this error

As a additional request
Is it possible to add one simple example layout based which will be based on CRUD and with all events like data changed etc are well demostrated , since provided example with service is bit difficult to understand.
 

DonManfred

Expert
Licensed User
Longtime User
I am using this library and the example posted on one of B4A tutorial series on internet.
There is a good reason why this library is in the Library archive.
.
It does not work any longer and it is no longer developed. Do NOT use the Library any longer.
 
Status
Not open for further replies.
Top