Firebase order error data

Hi I am having an issue recieven data from firebase.

My data in firebase is this:

-PLAYER1:
POSITION:2
NAME:ANDY
-PLAYER2:
POSITION:1
NAME:MARY

When I initialice the screen I call tag list and then for each tag I call the values position and name, I save all data in 3 lists and all work perfectly. This always work when I run the app for fisrt time.

I recieve this information:

PLAYER LIST(PLAYER1,PLAYER2)
NAME LIST(ANDY,MARY)
POSITION LIST(2,1)

THE PROBLEM IS HERE. when i change the screnn and return to first I call again the database but I recieven a differente order like this:

PLAYER LIST(PLAYER1,PLAYER2)
NAME LIST(MARY,ANDY)
POSITION LIST(1,2)

This is not the correct order and this is just happening when I change screens, As I said before when I run the app for first time all work perfectly, always!

I thought maybe the list was adding items but not, when I change a screen, I open the new one and close the last oen so the lisst are resets to empty.

Any idea???

When you add new tags in firebase it is sorted out in ascending order. (Only in firebase database)

But when you call tag list then it is not sorted out in ascending order. So you have to sort data according to your needs

1 Like

Yeah I know that when I call the tag list could be different and it doesnt matter for me actually, but look when I call for each value for each tag it has to be the same as firebase right?

So for example player 1, position is 2 and the name is andy in firebase but when I recieve the data and save in the lists the values have different order. player 1 has the values of player 2.

CORRECT DATA SAVED IN LISTS IN CORRECT ORDER:
PLAYER LIST(PLAYER1,PLAYER2)
NAME LIST(ANDY,MARY)
POSITION LIST(2,1)

THE PROBLEM IS HERE. when i change the screen and return to first I call again the database but I recieve a different order:

PLAYER LIST(PLAYER1,PLAYER2)
NAME LIST(MARY,ANDY)
POSITION LIST(1,2)

And for be clear it just happen when I change screens. always in firts time that I open the app I recieve the data correctly.

Retrieve the data once, and pass it to each screen, then parse it?

Also could you explain more why this is an issue?

Hahahah good song.

Well I am not need the data in the other screen. I mean the screen 1 has a listview with the data and the screen 2 is other thing like “about us” so it doesnt matter.

So when i open the app and open screen1 I recieve the data ok.
Then i open screen 2 and close screen 1, then I close screen 2 and open screen 1 again but here the data is wrong. :confused:

So for me the problem is that my data is saved wrong and I cant displayed property. If player 1 is index 1 so the values of her name and position has to be 1 and not different, are you understand me?

Are you using key-value pairs when storing things in Firebase? For example…

{
  "names": ["name1", "name2"],
  "placement": [1, 2],
  "players": ["player1", "player2"]
}

Or are you storing things in Firebase like…

{
  "players": ["player1", "player2"],
  "player1": {
    "name": "name1",
    "placement": 1,
  },
  "player2": {
    "name": "name2",
    "placement": 2,
  }
}

Based on what you posted, I feel you’re using key-value pairs which wouldn’t be best in this scenario.

Hey it is very simple man. Try to use web component. I mean when ever screen initialize download the names in terms of json format instead of calling firebase tag list

Just ref here.

You will get an idea.

This is my structure on firebase

Players:

 Player1
       Name:Andy
       Position:2
 Player2
       Name:Mary
       Position:1

This could be work but it is more complicate maybe I can use for a last solution and thank you I am really apreacciate your answer.

My question is if I am doing the correct process and the result is good at first time, why the values change when I change from screen to other screen?

What is the explanation?

Mostly firebase will store and retrieves value in terms of json format only. But this is the first time I m hearing after switch over of the screen data’s order changed. Actually at very first time how you are getting the same format only you have to get it whenever you switched in from another screen

But this method will give in the same order how it is stored

But I am sure get tag list will always sort the list

If possible share video

Yeah I know this issue is rare or maybe I am not seein something.
I attached you my blocks and the results.

This is the result when I call for the first time, thats the correct order of all data.

Then I switch between screens and this is the result. the order of tags is the same but values are wrong.

Can you share your firebase structure for the above mentioned project bucket ???

I see in your code that you do not have a procedure to save data to firebase, does this mean that you entered data directly to firebase ? If so, you should add it using the following format

"\"here put your data\""

Maybe this is causing the error

1 Like

firebase

This is my structure in firebase… the data is already in the way that dora said.

I tested with two firebase components and I believe now it works as it should

image

image

2 Likes

@Elaprendiz firebase.apk (5.2 MB)

try this apk, and tell me Is the order changes when you move in from s2 to s1

Yes it works normally. What did u do or what is the problem?

As i said i have tried web component + json method. So it won’t alter the data. I am not sure with exact reason for ur problem.

Have you tried the method suggested by dora?

I change bit to bit with dora suggestions and I found a rare thing that is a solution for me.

I am just add other firebase component BUT i dont use it. I mean there are 2 firebase components in the proyect but in blocks I just use one. So this is rare but it works.

And the second component has to be empty in project bucket, if not the error is still there.

When tested in designer properties, firebase1’s bucket is set to Clasificados and firebase2’s bucket is empty