title: How to keep Realm up-to-date across multiple background services in Android?
body: <p>I'm trying to write data on one service and accessing it from another service.
  The data I'm getting from another service is not updated, it's old copy.
  Restarting the app sometimes gets updated data.
  The services are both normal <code>Service</code> extended, so UI thread only.
  And I'm not keeping any <code>realm</code> instances open anywhere in the app.
  How do I ensure it's always new and updated one?</p>
  
  <p>Writing -</p>
  
  <p><code>data</code> is detached using <code>realm.copyFromRealm(...)</code></p>
  
  <pre><code>try (Realm realm = Realm.getDefaultInstance()) {
      if (realm != null) {
          realm.executeTransaction(new Realm.Transaction() {
              @Override
              public void execute(@NonNull Realm realm) {
                  data.setValue("New value ...");
  
                  realm.insertOrUpdate(data);
              }
          });
      }
  }
  </code></pre>
  
  <p>Reading -</p>
  
  <pre><code>Data data = null;
  try (Realm realm = Realm.getDefaultInstance()) {
      if (realm != null) {
          realm.executeTransaction(new Realm.Transaction() {
              @Override
              public void execute(@NonNull Realm realm) {
                  data = realm.copyFromRealm(realm.where(Data.class).equalTo("Id", id).findFirst());
              }
          });
      }
  }
  </code></pre>
  
  <p>Data -</p>
  
  <pre><code>public class Data {
      ...
      private String Value;        
      public String getValue() { return Value; }
      public void setValue(String v) { Value = v; }
      ...
  }
  </code></pre>
  
  <p>Edit -</p>
  
  <p>I ended up merging both services into one, which works for now. But I'll look forward if anyone can provide some tips or has a similar problem.</p>