Skip to content
Advertisement

I can’t store values in the database DAO android

Hi I can’t store values in the database DAO android. I have User.class:

JavaScript

DAO database:

JavaScript

My Dtababase class is:

JavaScript

My code

JavaScript

Now my code don’t store new User(i can’t print “ok you are pretty”).Why? I have another question: i know that when you store data in the database you use threads but what do threads allow you to do?

Advertisement

Answer

A problem is that you always create in a new database instance instead of having a singleton database.

Single instance (source):

JavaScript

You need a thread because the Room database does not allow operations on the main thread to prevent blocking the UI (source)

User contributions licensed under: CC BY-SA
2 People found this is helpful
Advertisement