ServerValue.TIMESTAMP returning 2 values?

我们两清 提交于 2020-01-07 03:48:22

问题


I use the following code to add a timestamp to a message:

Map<String, Object> postValues = post.toMap();
postValues.put("timeStamp", ServerValue.TIMESTAMP);

On the client side two timestamp values are printed out (one for the local creation date and one for the value from the server I think). How do I only print out the value which came from the server?

Side-note for Frank: The code below is called when the user presses the 'send' button. Thus, the messageViewHolder gets updated twice in my app (see related question). The viewHolder is updated once with the local time estimate and once with the server time. I want it to update the holder only with the server time (once) for practical purposes.

FriendlyMessage friendlyMessage = new FriendlyMessage("bla","bla","bla");

 String key = mFirebaseDatabaseReference.child(MESSAGES_CHILD).push().getKey();
 Map<String, Object> postValues =  friendlyMessage.toMap();
 postValues.put("creationDate", ServerValue.TIMESTAMP);
 childUpdates.put("/"+MESSAGES_CHILD+"/" + key, postValues);
 Map<String, Object> childUpdates = new HashMap<>();

 mFirebaseDatabaseReference.updateChildren(childUpdates);

来源:https://stackoverflow.com/questions/44860074/servervalue-timestamp-returning-2-values

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!