title: How to make generic AsyncTask for Android Room request
body: <p>So I'm using Android Room library to perform requests on a SQLite DB.</p>
  
  <p>I can't make requests on the UI thread, so I'm using AsyncTask.</p>
  
  <p>My app is simple, I juste want to be able to insert new Users into my database.</p>
  
  <p>So there is my UserDao.java :</p>
  
  <pre><code>@Dao
  public interface UserDao {
      @Insert
      long insert(User user);
  
      @Update
      void update(User user);
  
      @Delete
      void delete(User user);
  }
  </code></pre>
  
  <p>And there is my User.java : </p>
  
  <pre><code>@Entity
  public class User {
      @PrimaryKey(autoGenerate = true)
      private int id;
      private String name;
      private int age;
  
      // Getter / Setter
  }
  </code></pre>
  
  <p>And then, to perform my Insert request, I have to make an entire AsyncTask class : </p>
  
  <pre><code>public static class insertAsyncTask extends AsyncTask&lt;User, Void, User&gt; {
          private WeakReference&lt;Activity&gt; weakActivity;
          private UserDao dao;
  
          // Constructeur
          insertAsyncTask(Activity activity, UserDao dao) {
              this.weakActivity = new WeakReference&lt;&gt;(activity);
              this.dao = dao;
          }
  
          @Override
          protected User doInBackground(final User... params) {
              return this.dao.getById(this.dao.insert(params[0]));
          }
  
          @Override
          protected void onPostExecute(User u) {
              // Some code
          }
  </code></pre>
  
  <p>And finally, I'm calling the Insert like that : </p>
  
  <pre><code>new AppDatabase.insertAsyncTask(this, db.userDao()).execute(myUser);
  </code></pre>
  
  <p>So is it possible to make my AsyncTask class more generic ?
  I would like to be able to use this class for multiple requests (like Insert, Update, Delete ...).</p>
  
  <p>Or should I do a generic DAO instead ?</p>
  
  <p>Thanks in advance and sorry for my English ;)</p>