布尔值未出现在Firestore对象中

时间:2018-11-20 20:16:26

标签: android firebase google-cloud-firestore

我有一个Firebase集合,该集合通过将称为MessageThreads的对象存储为文档来跟踪用户的消息线程。这是该对象的类/构造函数:

public class MessageThread {
    private String partnerName;
    private String partnerID;
    private String threadID;
    private Message lastMessage;
    private boolean notificationsOn;


    public MessageThread() {

    }


    public MessageThread(String partnerName, String partnerID, String threadID, boolean notificationsOn) {
        this.partnerName = partnerName;
        this.partnerID = partnerID;
        this.threadID = threadID;
        this.notificationsOn = notificationsOn;
    }


    public MessageThread(String partnerName, String partnerID, String threadID, Message lastMessage, boolean notificationsOn) {
        this.partnerName = partnerName;
        this.partnerID = partnerID;
        this.threadID = threadID;
        this.lastMessage = lastMessage;
        this.notificationsOn = notificationsOn;
    }

    public String getPartnerID() {
        return partnerID;
    }

    public void setPartnerID(String partnerID) {
        this.partnerID = partnerID;
    }

    public String getThreadID() {
        return threadID;
    }

    public void setThreadID(String threadID) {
        this.threadID = threadID;
    }

    public boolean areNotificationsOn() {
        return notificationsOn;
    }

    public void setNotificationsOn(boolean notificationsOn) {
        this.notificationsOn = notificationsOn;
    }

    public String getPartnerName() {
        return partnerName;
    }

    public void setPartnerName(String user1) {
        this.partnerName = user1;
    }


    public Message getLastMessage() {
        return lastMessage;
    }

    public void setLastMessage(Message lastMessage) {
        this.lastMessage = lastMessage;
    }

}

在为新线程启动消息传递活动时,将notificationsOn布尔值设置为true,并使用第二个(4个参数)构造函数创建一个Thread对象:

 private void getSetThreadDetails(final String convoID) {

        final DocumentReference threadReference = mFirestore.collection("users").document(mSignedInUserID).collection("threads").document(convoID);


        threadReference.get().addOnCompleteListener(new OnCompleteListener<DocumentSnapshot>() {
            @Override
            public void onComplete(@NonNull Task<DocumentSnapshot> task) {
                if (task.isSuccessful()) {
                    DocumentSnapshot snapshot = task.getResult();

                    if (!snapshot.exists()) {
                        notificationsOn = true;
                        Log.d(TAG,"notifications when thread details set: " +String.valueOf(notificationsOn));
                        MessageThread newMessageThread = new MessageThread(mPartnerName, mPartnerID, convoID, notificationsOn);
                        threadReference.set(newMessageThread);

                    }



                }
            }
        });


    }

但是,在Firebase中,即使存储的MessageThread在被发送到Firebase之前就被设置为true,也不会显示notificationsOn的条目。它去哪里了?

1 个答案:

答案 0 :(得分:2)

您有一个notificationsOn的setter,但没有getter。 Firestore(通过JavaBean约定)需要使用正确的名称来找到该方法:

public boolean getNotificationsOn() {
    return this.notificationsOn;
}