【发布时间】:2020-12-29 09:05:34
【问题描述】:
我正在开发一个社交网络应用程序,用户可以在其中关注其他用户并喜欢他们的帖子,cmets ... 每当某个用户关注某人时,它会显示在另一个用户帐户的通知片段中,以通知他他有一个新的关注者。 问题是当用户点击取消关注时我无法删除通知。这是我尝试过的:
if ( holder.btn_follow.getText().toString().equals("follow"))
{
addNotifications(user.getId());
}
else{
FirebaseDatabase.getInstance().getReference("Notifications").child(user.getId()).removeValue();
}
这是我添加通知的方式:
private void addNotifications(String userid)
{
DatabaseReference reference = FirebaseDatabase.getInstance().getReference("Notifications").child(userid);
HashMap<String, Object> hashMap = new HashMap<>();
hashMap.put("userid", firebaseUser.getUid());
hashMap.put("text"," started following you");
hashMap.put("postid","");
hashMap.put("ispost",false);
reference.push().setValue(hashMap);
}
我的代码的问题在于,每当用户取消关注某人时,来自该用户的所有通知都会被删除,包括他的点赞和 cmets。我只想删除“开始关注你”。 这是它在 Firebase 数据库中的外观。
【问题讨论】:
-
请不要因为使用 android-studio 标签而标记问题:Android Studio 标签应该仅在您对 IDE 本身有疑问时使用,而不是您在其中编写(或想要编写)的任何代码。请参阅 when is it appropriate to remove an IDE tag、How do I avoid misusing tags? 和 the tagging guide。请改用 [android] 或其他相关标签。
-
哦,好的,谢谢。不会再这样做了
标签: android firebase firebase-realtime-database