1

hope you all would be fine... i am developing a simple app for testing and learning purposes that stores the name, email and image of the user into the ROOM DATABASE. i am a newbie to Room database i watched many tutorials on youtube to learn that how to implement ROOM in android apps. the main problem is that in Tutorials all of them are using AsyncTask to store info into ROOM. but when i followed those tutorials then i came to know that the AsyncTask has been deprecated, which is the main cause that i am not getting MyDatabase.getInstance() method inside my MainActivity. So tell me what to do right now.. what should i implement other than AsyncTask. Also i want to learn that how to store Images into RoomDatabase This is my Code where i am getting the error...

class InsertAsyncTask extends AsyncTask<User, Void, Void> {

    @Override
    protected Void doInBackground(User... users) {
          //this is the line where i am getting the error. getInstance method becomes red.
          //UserDatabase.getInstance(getApplicationContext()).dao().insertUser(users[0]);
        return null;
    }
}
Aqeel Mughal
  • 2,105
  • 2
  • 6
  • 14

1 Answers1

0

You can use RxJAVA to perform database operation with Room.

Ex.

Observable.fromCallable(()->UserDatabase.getInstance(getApplicationContext()).dao().insertUser(users[0]))
     .subscribeOn(Schedulers.io())
     .subscribe(...);

For Storing image in database, you can check below link How insert image in room persistence library?

From my point of view better solution is for storing image path rather than storing image in database.

Malay
  • 71
  • 9