Home add object to realm database on class that Inherited FirebaseMessagingService Inherited service (FCM)
Reply: 0

add object to realm database on class that Inherited FirebaseMessagingService Inherited service (FCM)

user8467 Published in September 19, 2018, 9:10 am

hello everybody i call below method (SaveMessage )at Public Constructor (onMessageReceived) FirebaseMessagingService for save String in realm but after get notification when get date from this table its null

   public class FireBaseService extends FirebaseMessagingService {

    public static  int NOTIFICATION_ID = 1;
    Handler handler;
    public void onMessageReceived(RemoteMessage remoteMessage) {



 public void SaveMessage(final String message){

           Realm realm = Realm.getDefaultInstance();
               realm.executeTransactionAsync(new Realm.Transaction() {
                   public void execute(Realm realm) {
                       SimpleDateFormat simpleDateFormatTime = new SimpleDateFormat("HH:mm", Locale.getDefault());
                       String strTime = simpleDateFormatTime.format(new Date());
                       Number currentIdNum = realm.where(MessagePojo.class).max("id");

                       int nextId;
                       if (currentIdNum == null) {
                           nextId = 1;
                       } else {
                           nextId = currentIdNum.intValue() + 1;
                       MessagePojo messagePojo =  realm.createObject(MessagePojo.class,nextId);


and i add change listener for this Realm table in one fragment.

thank you for your reading .

share|improve this question
  • @EpicPandaForce What is your comment communicating with my problem :| ?? and i close realm in last line ! – amin mahmoudi Apr 19 at 15:57
  • Because you are closing the background thread Realm before the transaction is committed, instead of closing the Realm that started the async transaction. So your transaction is never committed. – EpicPandaForce Apr 19 at 16:43

1 Answer 1

active oldest votes
up vote 0 down vote accepted
You need to login account before you can post.

About| Privacy statement| Terms of Service| Advertising| Contact us| Help| Sitemap|
Processed in 0.682371 second(s) , Gzip On .

© 2016 Powered by mzan.com design MATCHINFO