title: The AsyncTask API is deprecated in Android 11. What are the alternatives?
body: <p>Google is deprecating Android AsyncTask API in Android 11 and suggesting to use <code>java.util.concurrent</code> instead. you can check out the commit <a href="https://android-review.googlesource.com/c/platform/frameworks/base/+/1156409" rel="noreferrer">here</a></p>
  <pre><code> *
   * @deprecated Use the standard &lt;code&gt;java.util.concurrent&lt;/code&gt; or
   *   &lt;a href=&quot;https://developer.android.com/topic/libraries/architecture/coroutines&quot;&gt;
   *   Kotlin concurrency utilities&lt;/a&gt; instead.
   */
  @Deprecated
  public abstract class AsyncTask&lt;Params, Progress, Result&gt; {
  </code></pre>
  <p>If you’re maintaining an older codebase with asynchronous tasks in Android, you’re likely going to have to change it in future. My question is that what should be proper replacement of the code snippet shown below using <code>java.util.concurrent</code>. It is a static inner class of an Activity. I am looking for something that will work with <code>minSdkVersion 16</code></p>
  <pre><code>private static class LongRunningTask extends AsyncTask&lt;String, Void, MyPojo&gt; {
          private static final String TAG = MyActivity.LongRunningTask.class.getSimpleName();
          private WeakReference&lt;MyActivity&gt; activityReference;
  
          LongRunningTask(MyActivity context) {
              activityReference = new WeakReference&lt;&gt;(context);
          }
  
          @Override
          protected MyPojo doInBackground(String... params) {
              // Some long running task
              
          }
  
          @Override
          protected void onPostExecute(MyPojo data) {
  
              MyActivity activity = activityReference.get();
              activity.progressBar.setVisibility(View.GONE);
              populateData(activity, data) ;
          }     
  
  
      }
  </code></pre>