• 13

A PHP Error was encountered

Severity: Notice

Message: Undefined index: userid

Filename: views/question.php

Line Number: 191


File: /home/prodcxja/public_html/questions/application/views/question.php
Line: 191
Function: _error_handler

File: /home/prodcxja/public_html/questions/application/controllers/Questions.php
Line: 433
Function: view

File: /home/prodcxja/public_html/questions/index.php
Line: 315
Function: require_once

I have a component in my app that performs specific work when the database gets updated. In order to observe Room table, I need to use LiveData which requires me to pass LifecycleOwner. My component has nothing to do with any of the views so I don't have a Lifecycle. How can I observe on Room table without a reference to LifecycleOwner? I am using Kotlin and Coroutines.

You may use LiveData.observeForever(Observer). Do not forget to call LiveData.removeObserver(Observer) once you do not want to get updates anymore, as using this method you register an observer that will receive updates forever (as the method's name suggests). (Docs source)

  • 1
Reply Report