title: Realm objects can only be accessed on the thread they where created?
body: <p>In Realm, I am using <code>executeTransactionasync</code> method and in execute I am calling a method from utility class but when I am calling this method I am getting an error</p>
  
  <blockquote>
    <p>Realm objects can only be accessed on the thread they where created</p>
  </blockquote>
  
  <p><strong>Utils.class</strong></p>
  
  <pre><code>public void update_data(final Realm realm) {
      data bgTran = realm.where(data.class).equalTo("obj", "hello").findFirst();
      if(bgTran!= null){
          bgTran.settime("7 June");
      }
  }
  </code></pre>
  
  <p><strong>Activity Class Code</strong></p>
  
  <pre><code>realm.executeTransactionAsync(new Realm.Transaction() {
      @Override
      public void execute(final Realm bgRealm) {
          utils.update_data(realm);
      }
  }, new Realm.Transaction.OnSuccess() {
      @Override
      public void onSuccess() {
  
      }
  
  }, new Realm.Transaction.OnError() {
      @Override
      public void onError(Throwable error) {
          //gettting Error Realm objects can only be accessed on the thread they where created
      }
  });
  </code></pre>
  
  <p>Can anyone please tell me as the same realm is getting passed over the method call why is in UI thread then why am I getting the error.</p>
  
  <p>But When I am writing whole <code>executetransactionasync</code> in Util class then it is running perfectly fine.</p>
  
  <p><strong>Utils.class</strong></p>
  
  <pre><code>public void update_data(final Realm realm) {
       realm.executeTransactionAsync(new Realm.Transaction() {
           @Override
           public void execute(final Realm bgRealm) {
               data bgTran = bgRealm.where(data.class).equalTo("obj", "hello").findFirst();
               if(bgTran!= null){
                    bgTran.settime("7 June");
               }
           }
       }, new Realm.Transaction.OnSuccess() {
           @Override
           public void onSuccess() {
  
           }
  
       }, new Realm.Transaction.OnError() {
           @Override
           public void onError(Throwable error) {
  
           }
       });
  }
  </code></pre>
  
  <p><strong>Edit</strong> - The question is different from the marked question because there I know onpostExecute(UI Thread), doInBackground(Background Thread) they both access different Threads but the thing here is that as my code is in Activity Class so it will have a looper, so when I will call a method in util class now this class also can access to the looper because I am still in UI Thread then why this error is coming, <strong>Also if this error is coming then it should also come for the second case which I have mentioned but it is not</strong> ?</p>
  
  <p>Also, how can I write a common logic like I wrote in <code>update_data()</code> and use it anywhere? Because otherwise, I would have to write the same code again and again in the every Realm <code>executeTransactionasync</code> ?</p>