title: Realm Object is not updating
body: <p>I'm using Realm in my project and I was trying to update the realm object through RxJava. Realm object is successfully stored but the realm object is not updated.Actually i am performing all Read operations on UI thread and all WRITE operations on background thread using RxJava. Below is my code to perform all Realm's read and write operations.</p>
  
  <pre><code>class SuggestedFriendsController internal constructor(realm : Realm) {
  private var realm: Realm? = null
  
  init {
      this.realm = realm
  }
  
  fun addSuggestedFriends(requestPojo: RequestPojo?) {
      realm?.executeTransaction { realm -&gt;
          val realmFriends = RealmSuggestedFriends()
          realmFriends.friendEmail = requestPojo?.email
          realmFriends.friendImage = requestPojo?.image
          realmFriends.friendName = requestPojo?.name
          realmFriends.friendStatus = requestPojo?.status
          realmFriends.friendThumbImage = requestPojo?.thumb_image
          realmFriends.friendUid = requestPojo?.uid
          realmFriends.requestSent = "No"
          realm.copyToRealmOrUpdate(realmFriends)
      }
  }
  
  
  fun getRequestStateSync(uid: String?): String? {
        var res =  Realm.getDefaultInstance().use { realm -&gt;
            realm?.where(RealmSuggestedFriends::class.java)
                ?.equalTo("friendUid", uid)
                ?.findFirst()
        }
      return res?.requestSent
  }
  
  fun getAllAsync() = Observable.create&lt;List&lt;RealmSuggestedFriends&gt;&gt; { emitter -&gt;
      Realm.getDefaultInstance().use { realm -&gt;
          val results = realm?.where(RealmSuggestedFriends::class.java)
                  ?.findAll()
          emitter.onNext(realm?.copyFromRealm(results)!!)
      }
  }.flatMapIterable { list -&gt; list }
          .subscribeOn(Schedulers.io())
          .observeOn(AndroidSchedulers.mainThread())
  
  fun updateSuggestedFriendAsync(uid: String?, request_type: String?) =
          Single.create&lt;String&gt;{emitter -&gt;
              Realm.getDefaultInstance().use {realm -&gt;
                      realm?.executeTransaction{ realm -&gt;
                          var suggested = realm.where(RealmSuggestedFriends::class.java)
                                  .equalTo("friendUid", uid)
                                  .findFirst()!!
                          suggested.requestSent = request_type
                          realm.insertOrUpdate(suggested)
                      }
                  emitter.onSuccess("success")
                  }
              }.observeOn(AndroidSchedulers.mainThread())
          .subscribeOn(Schedulers.io())
  </code></pre>
  
  <p>}</p>
  
  <p>Below is my activity code. Here the variable <code>suggestedFriendController?.getRequestStateSync(friend_uid)</code> value is remain unchanged even its value is changed in the database. </p>
  
  <pre><code>class SFriend : AppCompatActivity(){
  private var image : NewCircularImagview ?= null
  private var name : AppCompatTextView ?= null
  private var addFriend : AppCompatButton ?= null
  private var imageUrl : String ?= null
  private var toolbar : Toolbar ?= null
  private var toolbar_text : TextView ?= null
  private var progressBar : ProgressBar ?= null
  private var friend_uid : String ?= null
  private var databaseReference: DatabaseReference? = null
  private var uid: String? = null
  private var compositeDisposable : CompositeDisposable ?= null
  private var realm : Realm ?= null
  private var suggestedFriendController : SuggestedFriendsController ?= null
  private var request_state : String ?= null
  
  override fun onCreate(savedInstanceState: Bundle?) {
      super.onCreate(savedInstanceState)
      setContentView(R.layout.suggested_friend_profile)
      initialize()
    friend_uid = intent.getStringExtra("friend_uid")
    imageUrl = intent.getStringExtra("imageurl")
    name?.text = intent.getStringExtra("name")
    request_state = suggestedFriendController?.getRequestStateSync(friend_uid)
      if (request_state?.equals("No")!!){
          addFriend?.setText("Send Request")
      }else{
          addFriend?.text = "Cancel Request"
      }
  }
  private fun initialize() {
  compositeDisposable = CompositeDisposable()
  databaseReference = FirebaseDatabase.getInstance().reference
  databaseReference?.keepSynced(true)
  uid = FirebaseAuth.getInstance().currentUser?.uid
  progressBar = findViewById(R.id.progress_bar)
  image = findViewById(R.id.profile_pic)
  name = findViewById(R.id.name)
  addFriend = findViewById(R.id.addFriend)
  toolbar = findViewById(R.id.toolbar)
  toolbar_text = toolbar?.findViewById(R.id.toolbar_text1)
  toolbar_text?.visibility = View.VISIBLE
  setSupportActionBar(toolbar)
  supportActionBar?.setDisplayHomeAsUpEnabled(true)
  getSupportActionBar()?.setHomeButtonEnabled(true)
  realm = Realm.getDefaultInstance()
  suggestedFriendController = realm?.let { r-&gt; SuggestedFriendsController(r) }
  }
  
  override fun onStart() {
      super.onStart()
      progressBar?.visibility = View.VISIBLE
      Picasso.with(this).load(imageUrl!!).into(image,object :Callback{
          override fun onSuccess() {
              progressBar?.visibility = View.GONE
          }
  
          override fun onError() {
              showMessage("image loading failed")
          }
      })
      addFriend?.setOnClickListener {
          addFriend?.isEnabled = false
          if (request_state?.equals("No")!!) {
              sendRequest(friend_uid)
          }else{
              cancelRequest(friend_uid)
          }
      }
  }
  
  private fun cancelRequest(friend_uid: String?) {
      Single.create&lt;String&gt;{ subscriber -&gt;
          databaseReference
                  ?.child("friend_requests")
                  ?.child(uid)
                  ?.child(friend_uid)
                  ?.removeValue()
                  ?.addOnCompleteListener { task -&gt;
                      if (task.isSuccessful) {
                          if (!subscriber.isDisposed) {
                          subscriber.onSuccess("success")
                          }
                      }else{
                          subscriber.onError(Throwable("error in cancel request"))
                      }
                  }
      }.subscribeOn(Schedulers.io())
              .observeOn(AndroidSchedulers.mainThread())
              .flatMap { Single.create&lt;String&gt;{ subscriber -&gt;
                          databaseReference
                                  ?.child("friend_requests")
                                  ?.child(friend_uid)
                                  ?.child(uid)
                                  ?.removeValue()
                                  ?.addOnCompleteListener { task -&gt;
                                      if (task.isSuccessful){
                                          if (!subscriber.isDisposed){
                                              subscriber.onSuccess("success")
                                          }
                                      }else{
                                          subscriber.onError(Throwable("error in cancel request"))
                                      }
                                  }
                       }.subscribeOn(Schedulers.io())
              }
              .subscribe({
                  t1 -&gt; showMessage(t1)
                  addFriend?.text = "Send Request"
                  addFriend?.isEnabled = true
                  suggestedFriendController?.updateSuggestedFriend(friend_uid!!,"No")
              },{
                  t2 -&gt; showMessage(t2.message)
              })
  }
  
  private fun showMessage(message : String?) {
      Toast.makeText(this,message,Toast.LENGTH_SHORT).show()
  }
  
  private fun sendRequest(friend_uid : String?){
     var d =  Single.create&lt;String&gt;{ subscriber -&gt;
                  databaseReference
                  ?.child("friend_requests")
                  ?.child(uid)
                  ?.child(friend_uid)
                  ?.child("request_type")
                  ?.setValue("sent")
                  ?.addOnCompleteListener { task -&gt;
                      if (task.isSuccessful){
                          if (!subscriber.isDisposed){
                              subscriber.onSuccess("success")
                          }
                      }else{
                          subscriber.onError(Throwable("request failed"))
                      }
                  }
      }.subscribeOn(Schedulers.io())
              .observeOn(AndroidSchedulers.mainThread())
              .flatMap { Single.create&lt;String&gt; { subscriber -&gt;
                  databaseReference
                          ?.child("friend_requests")
                          ?.child(friend_uid)
                          ?.child(uid)
                          ?.child("request_type")
                          ?.setValue("received")
                          ?.addOnCompleteListener { task -&gt;
                              if (task.isSuccessful){
                                  if (!subscriber.isDisposed){
                                      subscriber.onSuccess("sent")
                                  }
                              }else{
                                  subscriber.onError(Throwable("request failed"))
                              }
                          }
                  }.subscribeOn(Schedulers.io())
              }.flatMap {
         suggestedFriendController?.updateSuggestedFriendAsync(friend_uid,"Yes")
     }.subscribe({
        t1: String? -&gt; showMessage(t1)
          addFriend?.text = "Delete Request"
          addFriend?.isEnabled = true
      },{
          t2 -&gt; showMessage(t2.message)
      }
      )
     compositeDisposable?.add(d)
  }
  
  override fun onBackPressed() {
      super.onBackPressed()
      finish()
  }
  
  override fun onStop() {
      super.onStop()
      compositeDisposable?.clear()
  }
  
  override fun onDestroy() {
      super.onDestroy()
      realm?.close()
  }
  </code></pre>
  
  <p>}</p>
  
  <p>Below code is my Realm model.</p>
  
  <pre><code>open class RealmSuggestedFriends : RealmObject(){
  @Required
  @PrimaryKey
  var friendUid : String ?= null
  
  @Required
  var friendName : String ?= null
  
  @Required
  var friendEmail : String ?= null
  
  @Required
  var friendStatus : String ?= null
  
  @Required
  var friendImage : String ?= null
  
  @Required
  var friendThumbImage : String ?= null
  
  @Required
  var requestSent : String ?= null
  }
  </code></pre>
  
  <p>I need your suggestions to make it work. Help me </p>