title: Understanding CompositeDisposable in RxJava + Kotlin
body: <p>I am using RxJava for form validation for validating username and password.
  My use-case is pretty simple if both the fields satisfy respective condition then enable the login button else to disable it.
  following is my code.</p>
  
  <pre><code>
      lateinit var subscriptions: CompositeDisposable
      private fun validateForm() {
          val emailObservable = viewBinding.detUserName.editText.textChangeEvents()
              .skipInitialValue()
              .map { isValidEmail(it.text) || isValidPhoneNumber(it.text) }
              .doOnDispose {
                  Log.i("disposed", "emailObservable")
              }
  
  
          val passwordObservable = viewBinding.detPassword.editText.textChangeEvents()
              .skipInitialValue()
              .map { !TextUtils.isEmpty(it.text) }
              .doOnDispose {
                  Log.i("disposed", "passwordObservable")
              }
  
          val disposable = Observable.combineLatest(emailObservable, passwordObservable,
              BiFunction&lt;Boolean, Boolean, Boolean&gt; { t1, t2 -&gt; t1 &amp;&amp; t2 }).subscribeOn(Schedulers.io())
              .observeOn(AndroidSchedulers.mainThread())
              .subscribe {
                  viewBinding.bLogin.isEnabled = it
              }
          subscriptions.add(disposable)
      }
  
  fun isValidEmail(target: CharSequence): Boolean {
          return !TextUtils.isEmpty(target) &amp;&amp; android.util.Patterns.EMAIL_ADDRESS.matcher(target).matches()
      }
  
      fun isValidPhoneNumber(target: CharSequence): Boolean {
          return !TextUtils.isEmpty(target) &amp;&amp; Pattern.compile("(05|9665)[0-9]{8}").matcher(target).matches()
      }
  </code></pre>
  
  <p>I am <strong>subscription</strong> is a CompositeDisposable object reference which i am creating in onCreate and onResume(if not created or already cleared/disposed)
  and disposing it in onStop()</p>
  
  <p><strong>Edit</strong></p>
  
  <p><strong>following is part of my base fragment</strong></p>
  
  <pre><code> override fun onResume() {
          super.onResume()
          createDisposable()
      }
  
      protected fun createDisposable() {
          if (!this::subscriptions.isInitialized) {
              subscriptions = CompositeDisposable()
          }
      }
     override fun onStop() {
          super.onStop()
          disposeAll()
      }
  
      protected fun disposeAll() {
          if (this::subscriptions.isInitialized) {
              subscriptions.clear()
          }
      }
  
  </code></pre>
  
  <p><strong>my login fragment</strong></p>
  
  <pre><code>override fun onResume() {
          super.onResume()
          validateForm()
      }
  </code></pre>
  
  <p>For the first time <strong>Observable.combineLatest</strong> is working fine, but the problem is once the app goes into the background and resumes it's not firing again.
  when it went into background onStop() calls clear the compositeDisposable disposing of all the disposables, when it resumes I am re-adding new instance of disposables to compositeDisposable still, it's not firing.
  I am not able to figure out a way to fix this, any leads will be appreciated.</p>