I'm writing a message to my Room db to then send it to the server when this is succesful I update the message in the database.
When I try this from a Worker (WorkManager) the LiveData that holds the messages doesnt update even tho the message gets written to the db.
Small example (insert doesnt update LiveData but when I restart the app the message shows up):
override fun doWork(): Result {
appDatabase = appDatabase(applicationContext)
val messageId = inputData.getString("messageId", "") ?: ""
val message = appDatabase.messageDao().getMessage(messageId)
appDatabase.messageDao().insertMessage(Message(message.conversationId, "XYZ 234234234234", "test", "test", SimpleDateFormat("yyyy-MM-dd-HH-mm-ss", Locale.GERMANY).format(Date()), false))
return Result.SUCCESS
}
Outside of the Worker everything works fine.