title: How to dispose Rx in WorkManager?
body: <p>I implemented an <code>AlarmManager</code> to send notifications when user adds a due date to a Task. However, when the user turns off the device, all the alarms are lost. Now I'm updating the <code>BroadcastReceiver</code> to receive an <code>android.intent.action.BOOT_COMPLETED</code> and reschedule all the alarms set to each task.</p>
  
  <p>My first attempt was to get an <code>Rx Single</code> with all the tasks where the due date is higher than the current time inside the <code>BroadcastReceiver</code>, then reschedule all the alarms. The issue is I'm not able to dispose the <code>Observable</code> once the <code>BroadcastReceiver</code> has no lifecycle. Also, <a href="https://stackoverflow.com/a/45706973/6100078">it seems that this is not a good approach</a>.</p>
  
  <p>During my researches, the <code>IntentService</code> was a good solution for this case, but I'm getting into the new <code>WorkManager</code> library and the <code>OneTimeWorkRequest</code> looks like a good and simple solution.</p>
  
  <p>The <code>Worker</code> is being called and executing correctly, but I'm not able to dispose the <code>Observable</code> because the <code>onStopped</code> method is never called.</p>
  
  <p>Here is the implementation, based on <a href="https://stackoverflow.com/a/51502464/6100078">this snippet</a>:</p>
  
  <pre><code>class TaskAlarmWorker(context: Context, params: WorkerParameters) :
      Worker(context, params), KoinComponent {
  
      private val daoRepository: DaoRepository by inject()
  
      private val compositeDisposable = CompositeDisposable()
  
      override fun doWork(): Result {
          Timber.d("doWork")
  
          val result = LinkedBlockingQueue&lt;Result&gt;()
  
          val disposable =
              daoRepository.getTaskDao().getAllTasks().applySchedulers().subscribe(
              { result.put(Result.SUCCESS) },
              { result.put(Result.FAILURE) }
          )
  
          compositeDisposable.add(disposable)
  
          return try {
              result.take()
          } catch (e: InterruptedException) {
              Result.RETRY
          }
      }
  
      override fun onStopped(cancelled: Boolean) {
          Timber.d("onStopped")
          compositeDisposable.clear()
      }
  }
  </code></pre>
  
  <ul>
  <li>Is <code>WorkManager</code> a good solution for this case?</li>
  <li>Is it possible to dispose the <code>Observable</code> correctly?</li>
  </ul>