Я получаю сообщение об ошибке при использовании WorkManager.
Невозможно получить доступ к базе данных в главном потоке, поскольку он может потенциально заблокировать пользовательский интерфейс на длительный период времени.
Мой код
val x = WorkManager.getInstance().getStatusesByTag(vm.workTag)
x.observeForever { }
Если я не использую метод, соблюдайте все условия работы
Мой журнал
Caused by: java.lang.IllegalStateException: Cannot access database on the main thread since it may potentially lock the UI for a long period of time.
at androidx.room.RoomDatabase.assertNotMainThread(RoomDatabase.java:223)
at androidx.room.RoomDatabase.beginTransaction(RoomDatabase.java:269)
at androidx.work.impl.model.WorkSpecDao_Impl$11.compute(WorkSpecDao_Impl.java:928)
at androidx.work.impl.model.WorkSpecDao_Impl$11.compute(WorkSpecDao_Impl.java:914)
at androidx.lifecycle.ComputableLiveData$2.run(ComputableLiveData.java:101)
at androidx.arch.core.executor.testing.InstantTaskExecutorRule$1.executeOnDiskIO(InstantTaskExecutorRule.java:38)
at androidx.arch.core.executor.ArchTaskExecutor.executeOnDiskIO(ArchTaskExecutor.java:96)
at androidx.arch.core.executor.ArchTaskExecutor$2.execute(ArchTaskExecutor.java:53)
at androidx.lifecycle.ComputableLiveData$1.onActive(ComputableLiveData.java:70)
at androidx.lifecycle.LiveData$ObserverWrapper.activeStateChanged(LiveData.java:418)
at androidx.lifecycle.LiveData.observeForever(LiveData.java:214)
at androidx.lifecycle.MediatorLiveData$Source.plug(MediatorLiveData.java:141)
at androidx.lifecycle.MediatorLiveData.onActive(MediatorLiveData.java:118)
at androidx.lifecycle.LiveData$ObserverWrapper.activeStateChanged(LiveData.java:418)
at androidx.lifecycle.LiveData.observeForever(LiveData.java:214)
at org.kadance.ftvideo.view.VideoPlayerActivity.onCreate(VideoPlayerActivity.kt:827)
at android.app.Activity.performCreate(Activity.java:6237)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1107)
at androidx.test.runner.MonitoringInstrumentation.callActivityOnCreate(MonitoringInstrumentation.java:667)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2369)