title: How to get currently logged in user using user id in with AsyncTask
body: <p>Am using the MVVM android architecture.I want to get the currently signed in user using the a user_id that i stored in my shared preference class. </p>
  
  <p>I tried getting the user directly from the room database but had an error stating that i have to do it in the background thread.I'm trying to use AsyncTask but its not working out.</p>
  
  <p>my user Model</p>
  
  <pre><code>@Entity(tableName = "users")
  public class User {
   @PrimaryKey(autoGenerate = true)
      private long id;
      private String name;
      private String email;
      private String imageUrl;
      public User(String name, String email, String imageUrl) {
      this.name = name;
      this.email = email;
      this.imageUrl = imageUrl;
     }
    public User() {
    }
    my getters and setters here
  }
  </code></pre>
  
  <p>my database</p>
  
  <pre><code> @Database(entities = {AnimalTreatment.class, Animals.class, 
   FarmTask.class, Finance.class, LandAndCrop.class, Machine.class, 
   User.class}, version = 1)
  
   public abstract class AppDatabase extends RoomDatabase {
      private static AppDatabase instance;
      public static synchronized AppDatabase getInstance(Context context) {
          if (instance == null) {
              instance = 
   Room.databaseBuilder(context.getApplicationContext(), AppDatabase.class, 
   "database")
                  .fallbackToDestructiveMigration()
                  .build();
          }
          return instance;
      }
      public abstract UserDao userDao();
  }
  </code></pre>
  
  <p>my Dao</p>
  
  <pre><code> @Dao
   public interface UserDao {
       @Query("SELECT * FROM users WHERE id = :id")
       User getUser(long id);
   }
  </code></pre>
  
  <p>my Repository class</p>
  
  <pre><code> public class UserRepository {
       public UserDao userDao;
       private User user;
       private long userId;
  
       public UserRepository(Application application) {
           userId = Settings.getUserId();
           AppDatabase database = AppDatabase.getInstance(application);
           userDao = database.userDao();
       }
       public User getCurrentUser(){
           new getCurrentUser(userId,userDao).execute();
           return user;
       }
  
     ####This where am confussed how do i return a user in the 
     getCurrentUser() above ###
  
       public static class getCurrentUser extends AsyncTask&lt;Void, Void, 
   User&gt; {
          private long userId;
          private User user;
          private UserDao userDao;
          public getCurrentUser(long userId, UserDao userDao) {
              this.userId = userId;
              this.userDao = userDao;
          }
          @Override
          protected User doInBackground(Void... voids) {
     //            user = new UserRepository(UserRepository.this);
              user = userDao.getUser(userId);
              return user;
          }
      }
  }
  </code></pre>
  
  <p>my viewModel class</p>
  
  <pre><code> public class UserViewModel extends AndroidViewModel {
      private static final String TAG = "UserViewModel";
       private UserRepository userRepository;
       private User user;
       private UserDao userDao;
       public UserViewModel( Application application) {
          super(application);
          Log.d(TAG, "UserViewModel: Instantiation of UserViewModel");
          userRepository = new UserRepository(application);
       }
       public User getCurrentUser() {
          user = userRepository.getCurrentUser();
          return user;
        }
      }
  
  I want to get the currently signed in user from my database(room)
  </code></pre>