I save in my bank using sugar every time I get a new notification, it works correctly, then in a fragment I populate a recycleview with all the database notifications, it also works correctly, but now when I try to delete from the database by id I can not, my database returns null for some ids (see the debug image), I have tried to understand but I can not understand why.
Bank addition code:
public void onMessageReceived(RemoteMessage remoteMessage) {
SugarContext.init( this );
Log.d("igr", "Mensagem Recebida");
if (remoteMessage.getData().size() > 0) {
Log.d("igr", "Message data payload: " + remoteMessage.getData());
String titulo = remoteMessage.getData().get("title");
String mensagem = remoteMessage.getData().get("text");
try{
Notificacao notificacao= new Notificacao(titulo,mensagem);
SugarRecord.save(notificacao);
SugarContext.terminate();
}catch (Exception e){
Log.d("igr", "Erro ao salvar notificacao no DB: " + e);
SugarContext.terminate();
}
My template:
package br.com.igoroliv.youtubecanal.DataBase;
import com.orm.dsl.Table;
/**
* Created by igord on 03/07/2017.
*/
@Table
public class Notificacao {
private Long id;
private String titulo;
private String texto;
public Notificacao(){
}
public Notificacao(String titulo, String texto) {
this.titulo = titulo;
this.texto = texto;
}
/* gets e sets */
public Long getId() {
return id;
}
public String getTitulo() {
return titulo;
}
public String getTexto() {
return texto;
}
}