Firebase Realtimedatabase

Status
Not open for further replies.

fredo

Well-Known Member
Licensed User
Firebase Database REST and REALTIME Testproject "16r"

While working on my promise from #35 above ("...build a demo project with user login over RULES settings") I thought it would be a good idea to upload the project now
even if the Rules collection (Groups, Members, Readers, Admins, ...) isn't ready today.

For best result use the lib 1.24 or higher.

Due to the hints of @DonManfred the Realtime-part works so far that a user can log in via GoogleSignIn an make posts in the typical NoSQL fashion.

Remark:
This is intended to learn the basic moves in a Firebase Database TEST environment.
Never use this testproject for a PRODUCTIVE database.

10-10-_2016_18-20-58.jpg


10-10-_2016_18-22-18.jpg

10-10-_2016_18-23-22.jpg

You might need to know this for the Firebase console setup: 10-10-_2016_18-25-53.jpg

 

Attachments

  • fredo_FiBaDb_tester_16r.zip
    82.4 KB · Views: 407
Last edited:

cas6678

Active Member
Licensed User
Hello,

I try with the code post #35 by @fredo , thanks

I've error in this line:

B4X:
  ref.updateChildren(childUpdates)      ' <-- This is the "atomic" update. One start of transaction no matter how many elements the map has

Logs:

B4X:
Error occurred on line: 185 (Main)
java.lang.ClassCastException: anywheresoftware.b4a.objects.collections.Map cannot be cast to java.util.Map
    at de.donmanfred.DatabaseReferenceWrapper.updateChildren(DatabaseReferenceWrapper.java:212)
    at java.lang.reflect.Method.invoke(Native Method)
    at anywheresoftware.b4a.shell.Shell.runVoidMethod(Shell.java:748)
    at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:343)
    at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:247)
    at java.lang.reflect.Method.invoke(Native Method)
    at anywheresoftware.b4a.ShellBA.raiseEvent2(ShellBA.java:134)
    at anywheresoftware.b4a.BA.raiseEvent2(BA.java:157)
    at anywheresoftware.b4a.debug.Debug.delegate(Debug.java:259)
    at com.zona.protegida.main._testfunction_updatechildren(main.java:436)
    at com.zona.protegida.main._activity_resume(main.java:428)
    at java.lang.reflect.Method.invoke(Native Method)
    at anywheresoftware.b4a.shell.Shell.runMethod(Shell.java:703)
    at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:340)
    at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:247)
    at java.lang.reflect.Method.invoke(Native Method)
    at anywheresoftware.b4a.ShellBA.raiseEvent2(ShellBA.java:134)
    at anywheresoftware.b4a.BA.raiseEvent(BA.java:153)
    at com.zona.protegida.main.afterFirstLayout(main.java:108)
    at com.zona.protegida.main.access$000(main.java:17)
    at com.zona.protegida.main$WaitForLayout.run(main.java:80)
    at android.os.Handler.handleCallback(Handler.java:739)
    at android.os.Handler.dispatchMessage(Handler.java:95)
    at android.os.Looper.loop(Looper.java:158)
    at android.app.ActivityThread.main(ActivityThread.java:7231)
    at java.lang.reflect.Method.invoke(Native Method)
    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1230)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1120)

If comment this line I can read the change of the database (firebase console) in realtime (work), but can`t write in it.
 

cas6678

Active Member
Licensed User
something I do wrong

Create a button to send.

B4X:
Sub bt_click
    Dim childUpdates As Map
    childUpdates.Initialize
    childUpdates.Put("Campo","Valor")
    ref.updateChildren(childUpdates)  
End Sub

First time click, work. Write in database, ok. But second time click stop app.

B4X:
java.lang.NullPointerException: Attempt to invoke virtual method 'boolean anywheresoftware.b4a.BA.subExists(java.lang.String)' on a null object reference
    at de.donmanfred.DatabaseReferenceWrapper$5.onComplete(DatabaseReferenceWrapper.java:233)
    at com.google.android.gms.internal.zzajb$20.run(Unknown Source)
    at android.os.Handler.handleCallback(Handler.java:739)
    at android.os.Handler.dispatchMessage(Handler.java:95)
    at android.os.Looper.loop(Looper.java:158)
    at android.app.ActivityThread.main(ActivityThread.java:7231)
    at java.lang.reflect.Method.invoke(Native Method)
    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1230)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1120)

what is wrong???
 

cas6678

Active Member
Licensed User
Now work,

I comment the sub...

B4X:
Sub Reference_onComplete(errorCode As Int, errorMessage As String, errObj As Object, dbref As Object)
 

fredo

Well-Known Member
Licensed User
...Please note that the wrap for the Query object is NOT finished...

While making good progress with the "Firebase Database Quickstart B4A" project (see attachment) we're now able to perform all authentications with automatically register new users in a "users" node. Also does the realtime fanout writing work.

B4X:
'     U1) * working: The user can log in to post individual messages
'     U2) -->Query needed: The user can browse through a list of posts made by _all users_
'     U3) -->Query needed: The user can browse through a list of posts made by _himself_
'     U4) * working: The user can add a post
'     U5) * working: The user can open any post to see the post message
'           -->Query needed: and a list of all comments to this post
'     U6) * working: The user can add a comment to an opened post

However, the work stucks at the point where we need to run a query on a childnode to fill a CustomListView.

17-10-_2016_09-49-03.jpg


17-10-_2016_09-49-27.jpg


17-10-_2016_13-08-03.jpg


17-10-_2016_15-47-01.jpg

Since I'm not sure how to use the Query object I need help on how to set the reference and parameters.

@DonManfred: Is the Query object under construction or did I miss something in the docu?
 

Attachments

  • fredo_FRealDb_Quick_12b.zip
    138.6 KB · Views: 262
Last edited:

cas6678

Active Member
Licensed User
I do not understand what is wrong.

My program is simple, there is only one button and pressing writes in the dataBase ...

puerta:abrir and after 3 seconds .... puerta:cerrar (door:eek:pen/close)

It works fine, but when I go out and I want to enter a second time sayme:

Error occurred

... Calls to setPersistenceEnabled() must be made before any other usage of FirebaseDatabase instance

Mi code

B4X:
#Region  Project Attributes
    #ApplicationLabel: Control Home
    #VersionCode: 1
    #VersionName:
    'SupportedOrientations possible values: unspecified, landscape or portrait.
    #SupportedOrientations: portrait
    #CanInstallToExternalStorage: False
#End Region

#Region  Activity Attributes
    #FullScreen: true
    #IncludeTitle: false
#End Region

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

Sub Globals
    Private boton As ImageView
    Private puerta1 As Boolean
    Private time1 As Long
    Dim realtime As FirebaseDatabase
    Dim ref As DatabaseReference
End Sub

Sub Activity_Create(FirstTime As Boolean)
    realtime.Initialize("Realtime")
    realtime.PersistenceEnabled = True
    realtime.goOnline
     ref.Initialize("Reference",realtime.getReferencefromUrl("https://controlhome-xxxxx.firebaseio.com/"))
    ref.addChildEventListener
    ref.addListenerForSingleValueEvent
    ref.addValueEventListener
    GeneralTimer.Initialize("GeneralTimer",300)
    GeneralTimer.Enabled=True
    boton.Initialize("boton")
    Activity.AddView(boton,10%x,10%y,40%x,20%y)
    boton.Bitmap=LoadBitmap(File.DirAssets,"llave.png")
    boton.Gravity=Gravity.FILL
    puerta1=False
End Sub

Sub boton_click
    Dim childUpdates As Map' ++++++++++++++++++++++++++++++++++++++++++++++++++++++
    childUpdates.Initialize
    childUpdates.Put("puerta1","abrir")
    ref.updateChildren(childUpdates)    ' +++++++++++++++++++++++++++++++++++++++++
    time1=DateTime.now
    puerta1=True
End Sub

Sub GeneralTimer_Tick
    If puerta1=True Then
        If time1+3000<DateTime.Now Then
            Dim childUpdates As Map' ++++++++++++++++++++++++++++++++++++++++++++++
            childUpdates.Initialize
            childUpdates.Put("puerta1","cerrar")
            ref.updateChildren(childUpdates)    ' +++++++++++++++++++++++++++++++++
            puerta1=False
        End If   
    End If
End Sub

Sub Activity_Resume

End Sub

Sub Activity_Pause (UserClosed As Boolean)

End Sub
 

Widget

Well-Known Member
Licensed User
Ha .... Manfred (@DonManfred) only deserves the latest and most up-do-date gadgets :)

I agree, but "old" to some may mean an iPhone 6. A lot of people upgrade their very usable iPhones and iPads to the latest and greatest from Apple. These people must have to have the "best" that Apple has to offer. I'm sure there are a lot of "almost new" Apple iPhones/iPads that are collecting dust out there that could find a good home at Don's place. (hint... hint... for "these people" that are listening) :rolleyes:
 

johndb

Active Member
Licensed User
Don, can you elaborate as to why you don't like iOS?
I have an absolute hatred for iOS as well. My previous post related to giving @DonManfred the latest and greatest was in jest as I know Manfred has a dislike for Apple and their OS. Having said that, it would appear that in order to gain a decent client base for my applications, I will have to provide iOS versions of my software as well :eek:
Long nights ahead doing research and app adaption in trying to satisfy both worlds. Money is the keyword in my development world. Unfortunately, iOS and Android are very, very different worlds and things that you can do it Android cannot be transferred to iOS as iOS is incapable of doing them :D Think OPEN (Android), CLOSED (Apple iOS) with regards to development environments :confused:

John
 
Last edited:

Widget

Well-Known Member
Licensed User
As a developer, I don't think iOS can be ignored. Not if the developer wants to eat. :cool:

According to Gartner Research, as of March 2016 Android has 84.1% of the worldwide smart phone market and iOS has only 14.8% (down from 17.9% last year). Yet developers still make more money from paid iOS apps than Android apps. Which goes to show you that Apple users are willing to pay for software and Android users want mostly free stuff. The trick is to make "free" Android software that makes the developer money. If Apple's market share continues to drop, maybe in 5 years time iOS won't matter any more.
 

m643

Member
Licensed User
Hi,

I'm trying to remove a node with removeValue, that's working fine but after I getting an error and the app is stopped working:

B4X:
java.lang.NullPointerException: Attempt to invoke virtual method 'boolean anywheresoftware.b4a.BA.subExists(java.lang.String)' on a null object reference
    at de.donmanfred.DatabaseReferenceWrapper$4.onComplete(DatabaseReferenceWrapper.java:197)
    at com.google.android.gms.internal.zzajs$20.run(Unknown Source)
    at android.os.Handler.handleCallback(Handler.java:751)
    at android.os.Handler.dispatchMessage(Handler.java:95)
    at android.os.Looper.loop(Looper.java:154)
    at android.app.ActivityThread.main(ActivityThread.java:6119)
    at java.lang.reflect.Method.invoke(Native Method)
    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:886)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:776)

I added the sub Reference_onComplete, but still I get this error "lib: NOTFOUND 'null_oncomplete"

B4X:
Sub Reference_onComplete(errorCode As Int, errorMessage As String, errObj As Object)
    Log($"ref_onCancelled(${errorCode},${errorMessage})"$)
End Sub
 
Status
Not open for further replies.
Top