Firebase DB with App Inventor tutorial

Is there any documentation anywhere on how to use Firebase with App Inventor? I have read just about everything that I can get my hands on, I have a good beginner's grasp of how to read and store data but I am looking for more. I am having some issues and it's because I do not understand how to manipulate my database.

I don't want someone to show me blocks to fix my problem, I want to figure it out myself. The best way to learn is from my mistakes.

1 Like

IMHO this will be a good place to start

2 Likes

There's a tutorial on the AI2 website, go to the "Resources" tab then click on "Tutorials" and scroll until you see the Firebase tutorial, for documentation you can click on the question mark next to the component in the experimental drawer and then click learn more for anything extra.
Links:
http://ai2.appinventor.mit.edu/reference/components/experimental.html#FirebaseDB (documentation)
http://appinventor.mit.edu/explore/ai2/firebase (tutorial)

2 Likes

also make sure you have a firebase account

1 Like

Hi guys. thanks for the suggestions. And yes, I already have a Firebase acct and database I am playing with here. I eventually get to where I want to be with it but I sure do waste a lot of time with trial and error.. I figure why not build a good foundation now so that from now on I won't have all this trouble figuring things out.

1 Like

More App Inventor oriented tutorials. Good luck, the best way to learn is to try things. :slight_smile:

http://kio4.com/appinventor/8BfirebaseDB.htm

https://rominirani.com/tutorial-mit-app-inventor-firebase-4be95051c325

3 Likes
2 Likes

I did a lot of reading and watching and I did learn a few things so it wasn't a waste of time but I'm not really finding what I need.

For example, when it comes to FirebaseDBs, is it better to read in my list of data.. edit the pairs that I need to edit, and then store the data back.. or can I read in only the pairs I need to edit, edit them, and store them back without having to deal with the entire list?

Here is a line of my database structure:

image

I'm using the 2: as my index and the rest is values.

If I have to read in the entire list (I'm using Dictionaries) then I will but if I can edit only the pairs I need I would prefer that. Is that possible and how would I do it?

It's things like this that I am wanting to learn.

1 Like

I advise experimenting with use of compound tags like "2/Points" to get directly to individual values.
You would want to be able to update your data with a tweezers after loading it with a shovel.

I plead ignorance .. I have never heard of "Compound Tags" .. where can I read about these?

I would love to use tweezers instead of a shovel.

If you examine the place in the Firebase web site where it shows the contents of your databases, they are shown as trees, with the root of the tree on the left, like a PC file system directory structure.

Each twig of this tree can be reached by a tag that looks like full path and file name of a PC file, like C:\Users\ABG\Dropbox\AI2\Projects\chess\chess.aia
except Firebase uses / in its tags instead of the \ that Windows uses in its file systems.
So if I used the Firebase tag
Users/ABG/Dropbox/Projects/chess/chess.aia I might retrieve a value for the contents of chess.aia, had I uploaded it there.

The term 'compound tag' is my idea.
The '/' functionality works.

Using the firebase component blocks (as you have shown in your example) you will have to call back the entire contents of tag "2" to your app in order to edit any item therein.

If you use the web component to store data on firebase as firebase lists, then you will be able to drill down and edit/retrieve individual tags within your list structure.
(note: you could use the firebase component blocks to do this but it would take a lot of work)

See here:

and here:

for how to do this

Also a word of warning, Firebase will happily create tags/nodes with numbers if you don't supply them, but it can get a bit upset if you provide the numbers as tags/nodes (especially 0 and 1).

Ahhhh.. I understand. Thats kind of what I was hoping to avoid. I was also using the wrong words earlier, when I said "If I have to read in the entire list (I'm using Dictionaries) then I will but if I can edit only the pairs I need I would prefer that." that's what I am already doing now. I am reading in Tag 2 and all of its value. I was wanting to drill down to the exact pair, edit it, and save the pair and be done. I now see I cannot do like I had hoped.

Which brings me to my current problem. I can login to my app using the acct data in Tag 1 .. load the data from Tag 2 .. and make an edit to a pair in Tag 2 just fine. But many times when I save the data for Tag 2 back I am overwriting it with the data in Tag1 except for the data in the pair I edited. Its confusing.

I am trying to use the same Read and Write routines (its just good programing not to duplicate routines) and I eventually will solve the issue through trial and error like I always do.. but sheesh!

If I get THAT kind of stuck then I will post some blocks and ask for help. But for now, "D*mn the Torpedoes!"

I am quickly realizing that I am at the end of my knowledge and do need some help now.

I start of with this example data set:

example04

At this point life is good. Here is the routine I am running along with the Read and Write routines:

example01

I read in my target data.. make the edit to the pair I need.. and save the target data back. I then read in the orginal user data.


..the rest of the read blocks are here but you get the idea

Its as lean and clean as I know how to make it. If I login to my app with lets say user #2 and want to edit the data for user #1 I end up with this:

example05

..with the exception of the pairs that I edited.. they saved my edit and are correct. Everything else seems to be from user 2. I'm confused!

Where are you getting global targetIndex from?

Ai2 lists are 1 based, you firebase data (tags) appear to be 0 based.

Also sign in as user2 ? How are you "signing in" ?

I define target global targetIndex in the routine immediately before and I even check that it is the correct value.

I do sign in as user 2.

I dont understand what you mean by "Ai2 lists are 1 based, your firebase data (tags) appear to be 0 based" .. maybe this is my problem? The tag I am using is what I am calling my user number (the 1, 2 and 3) so is that not "1 based" since there is 1 tag?

As I see it my mistake is someplace with my tags.. the design, or the use of.. so I think you may be on to something.

This could also be an issue, which I advised on earlier in the topic. It may be better to assign strings to users as opposed to numbers (user1, user2, user3).

I still do not understand your signing in process and how that might affect access to the data. I am assuming you are NOT using firebase authentication.....

Correct, I am not using Firebase authentication. The only reason I am using Firebase at all is because I need to share the data between all the users. Any user will be able to edit any record. That, and I already had a Firebase acct. Is there a better solution perhaps? Would Coud DB work better for my needs?

Your original warning appears to be what is happening here I think. Everything works fine when if I hard code the indexes but to me thats just sloppy and a lot of extra coding with duplicate routines.

You could also be trying to do things out of sync

Everything next to the red bar should be happening in the .GotValue event, but then you call readCCUserData again which could create an endless loop ?

hmm.. let me see if I can explain a little more of my logic.

I have one GotValue routine for FirebaseDB1. I use it to read in the userdata when a user logs in. Lets say I am user #1 and I login. I now have all my variables assigned with my data.

I toddle along and need to edit a data pair for another user. I change the 'index variable' and do a call to read in the new user data using the same read routine. I make my edit and save the data back. I then change the 'index variable' back to my user number and read in my data.. all using the same read and save routines and GotValue event. Is this not the best way to handle this? I am guessing not..

I do not understand why you say the blocks next to the red bar need to be moved to the GetValue event. Those are the blocks I am using to edit the other users data. If they are part of the GetValue event they will fire every time ANY user is read, including my own data when I login. Thats not what I need to happen.

This is where I am having trouble, my big picture logic. I only know so much about Databases and am trying to figure this out. None of this is in production so I am not opposed to going back to the drawing board and redesigning anything. I just want to know I am doing it right, and it works.