0

I am trying to sync my android devices for a dice multiplayer game. When one player rolls his dices I am sending the data to a Firebase Realtime Database. Upon changing the data all devices should be updated with the numbers the active player has rolled. Therefore I am reading every dataSnapshot from the firebase and parse it into a class of type 'Player'. UserId is the key that Firebase RD generates when pushing new data into it, so it should be unambiguously.

        public void onDataChange(DataSnapshot dataSnapshot) {

            int j = 0;

            playerList.clear();
            for (DataSnapshot snap : dataSnapshot.getChildren()) {
                playerList.add(snap.getValue(Player.class));
            }

            for (int i = 0; i < playerList.size(); i++) {
                Log.d("LOG", "Playerlist: '" + playerList.get(i).getUserId() + "' , Activeplayer: '" + activePlayer.getUserId() + "'");
                if (playerList.get(i).getUserId() == activePlayer.getUserId()) {
                    j = i;
                }
            }

Here is the log output from the second for iteration:

D/LOG: Playerlist: '-M4f0dWR3jkMBO4K45JU' , Activeplayer: '-M4f1axYujY78s-hmOQZ'
D/LOG: Playerlist: '-M4f15nuDetGUtky4_Tr' , Activeplayer: '-M4f1axYujY78s-hmOQZ'
D/LOG: Playerlist: '-M4f1axYujY78s-hmOQZ' , Activeplayer: '-M4f1axYujY78s-hmOQZ'

As you can see the third line matches so the if clause should catch - but it won't :(

I tried parsing it, using 'toString()' method, which did not change anything.

Doug Stevenson
  • 297,357
  • 32
  • 422
  • 441
kantejn
  • 25
  • 1
  • 4

0 Answers0