0

I am attempting to develop the below data structure in a Firebase database with my user object in order to store FCM tokens in my database and I am not sure of how to implement my array list of fcm tokens in the User object

What is the best method to handle the FCM tokens for storage and retrieval?

Structure

public class User {
    private String uId;
    private String name;
    private String email;

      public ArrayList<Boolean> fcmTokens = new ArrayList<>();
    public User(String uId, String name, String email) {
        this.uId = uId;
        this.name = name;
        this.email = email;

    }
    public User() {

    }

    public String getUid() {
        return uId;
    }

    public void setUid(String uId) {
        this.uId = uId;
    }

    public void setName(String name) {
        this.name = name;
    }

public String getName() {
        return name;
    }

 public String getEmail() {
        return email;
    }

    public void setEmail(String email){
       this.email = email;
    }

///// HOW TO IMPLEMENT ARRAYLIST
KENdi
  • 7,576
  • 2
  • 16
  • 31
CiarĂ¡nimo
  • 517
  • 1
  • 9
  • 21

1 Answers1

0

The registration tokens are something that changes during these scenarios . I don't see any use of storing the reason to store historical tokens. Also, another issue might be downloading all the tokens every time when you want to download user1uid. So, I would suggest something like this.

--users
  -user1uid
     -name
     -email
     -fcmtokens
        -user1token:valueofuser1Token

And update the token everytime a user visits your app by calling updateRegistrationToken in your home page by passing the registrationToken.

  func updateRegistrationToken(registrationToken: String) {
    let userTokenRef = ref.child("users").child(user1uid)
    userTokenRef.setValue(["token": registrationToken])
}
Community
  • 1
  • 1
viggy28
  • 760
  • 1
  • 10
  • 21