【发布时间】:2017-03-19 15:40:37
【问题描述】:
我正在尝试制作聊天应用程序,我使用领域将聊天历史存储在数据库中。我将我的用户 ID 和其他人员 ID 存储到数据库中。如何获取我的聊天记录和其他人的数据?这是我正在使用的查询,但我只得到我的聊天而不是其他的。
chathistorylist = chatrealm.where(Chat_history_pojo.class)
.equalTo("senderid", Session.getUserID(getApplicationContext()))
.equalTo("receiverid", getIntent().getStringExtra("rid"))
.findAll();
下面是我存储发送给其他人的消息的数据
chatrealm = Realm.getDefaultInstance();
chatrealm.beginTransaction();
Chat_history_pojo chatupdatepojo = chatrealm.createObject(Chat_history_pojo.class);
chatupdatepojo.setSenderid(Session.getUserID(getApplicationContext()));
chatupdatepojo.setReceiverid(getIntent().getStringExtra("rid"));
chatupdatepojo.setMessage(sendmessgae.getText().toString());
chatupdatepojo.setType("text");
chatrealm.commitTransaction();
chatrealm.close();
sendmessgae.setText("");
这就是我将其他人的消息存储到数据库中的方式
chatrealm = Realm.getDefaultInstance();
chatrealm.beginTransaction();
Chat_history_pojo chatupdatepojo = chatrealm.createObject(Chat_history_pojo.class);
chatupdatepojo.setSenderid(getIntent().getStringExtra("rid"));
chatupdatepojo.setReceiverid(Session.getUserID(getApplicationContext()));
chatupdatepojo.setMessage(intent.getStringExtra("msg"));
chatupdatepojo.setType("text");
chatrealm.commitTransaction();
chatrealm.close();
这是 POJO 类
public class Chat_history_pojo extends RealmObject{
String senderid;
String receiverid;
String message;
String type;
String sender_profile;
String reciever_profile;
public String getSender_profile() {
return sender_profile;
}
public void setSender_profile(String sender_profile) {
this.sender_profile = sender_profile;
}
public String getReciever_profile() {
return reciever_profile;
}
public void setReciever_profile(String reciever_profile) {
this.reciever_profile = reciever_profile;
}
public String getSenderid() {
return senderid;
}
public void setSenderid(String senderid) {
this.senderid = senderid;
}
public String getReceiverid() {
return receiverid;
}
public void setReceiverid(String receiverid) {
this.receiverid = receiverid;
}
public String getMessage() {
return message;
}
public void setMessage(String message) {
this.message = message;
}
public String getType() {
return type;
}
public void setType(String type) {
this.type = type;
}
}
【问题讨论】:
-
我认为
getIntent().getStringExtra("rid")或Session.getUserID(getApplicationContext())可能存在问题 -
是的,我已经修复了,我只收到了我发送的一侧历史记录,但没有收到其他用户历史记录
-
没问题谢谢你
标签: java android realm realm-mobile-platform