G
G
giksen2021-03-19 22:14:18
Java
giksen, 2021-03-19 22:14:18

How to properly wrap work with the REST API and the Room database in threads?

In my application, I implement work with the REST API using Retrofit, and work with the database using Room , the application is built on the MVVM pattern. Networking and database work can be very UI intensive, which I would like to avoid. Please tell me how it would be better for me to arrange the work with these "heavy" tasks in separate threads, which classes should be paid attention to. Videos, articles, your personal advice, I will be glad to everything))

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
Denis Zagaevsky, 2021-03-20
@zagayevskiy

Retrofit itself goes to the network on the background, the system will not let you go to the network on the ui thread.
As for the room - it seems that it also does not allow you to go into yourself with a ui thread, in any case, they write so on the Internet. I haven't worked with it myself, so I'm not sure.
Pay attention to RxJava or Kotlin coroutines.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question