title: Unique OneTimeWorkRequest in Workmanager
body: <p>We are using OneTimeWorkRequest to start background task in our project. </p>
  
  <ol>
  <li>At application start, we are starting the OneTimeWorkRequest (say req A) </li>
  <li>Depends on user's action we start the same work request A.</li>
  </ol>
  
  <p>At some cases, if the app gets killed when the work request A is in progress, Android automatically restarts the request A when the app restarts. Once again we are also starting the request A again. So two instances of the request A runs in parallel and leads to a deadlock. </p>
  
  <p>To avoid this, I did below code in app start to check if the worker is running but this always returns false. </p>
  
  <pre><code>public static boolean isMyWorkerRunning(String tag) {
          List&lt;WorkStatus&gt; status = WorkManager.getInstance().getStatusesByTag(tag).getValue();
          return status != null;
      }
  </code></pre>
  
  <p>Is there a better way to handle this?</p>
  
  <p>I checked the beginUniqueWork(). Is it costlier if I have only one request?</p>
  
  <p><strong>Edit 2:</strong>
  This question is about unique One time task. For starting unique Periodic task we had a separate API enqueueUniquePeriodicWork(). But we did not have an API for starting unique onetime work. I was confused to use between continuation object or manually check and start approach. </p>
  
  <p>In recent build they Android added new api for this enqueueUniqueWork(). This is the exact reason they mentioned in their release notes. </p>
  
  <blockquote>
    <p>Add WorkManager.enqueueUniqueWork() API to enqueue unique
    OneTimeWorkRequests without having to create a WorkContinuation.
    <a href="https://developer.android.com/jetpack/docs/release-notes" rel="noreferrer">https://developer.android.com/jetpack/docs/release-notes</a></p>
  </blockquote>