Skip to content

Tarik Billa

  • Web Development
    • html
    • vue.js
    • laravel
    • css
    • javascript
    • jquery
    • node.js
    • php
    • asp.net
  • Programming
    • python
    • java
    • c
    • c++
    • c#
  • git
  • android

android-livedata

Observing LiveData from ViewModel

December 18, 2022 by Tarik

In this blog post by Google developer Jose AlcĂ©rreca it is recommended to use a transformation in this case (see the “LiveData in repositories” paragraph) because ViewModel shouldn’t hold any reference related to View (Activity, Context etc) because it made it hard to test.

Categories android Tags android, android-architecture-components, android-livedata, android-viewmodel Leave a comment

MutableLiveData: Cannot invoke setValue on a background thread from Coroutine

November 17, 2022 by Tarik

Use liveData.postValue(value) instead of liveData.value = value. It called asynchronous. From documentation: postValue – Posts a task to a main thread to set the given value.

Categories kotlin Tags android-livedata, kotlin, kotlin-coroutines Leave a comment

Difference of setValue() & postValue() in MutableLiveData

October 24, 2022 by Tarik

Based on the documentation: setValue(): Sets the value. If there are active observers, the value will be dispatched to them. This method must be called from the main thread. postValue(): Posts a task to a main thread to set the given value. If you called this method multiple times before a main thread executed a … Read more

Categories android Tags android, android-livedata, mutablelivedata Leave a comment
Newer posts
← Previous Page1 … Page4 Page5

Tarik Billa

Software Engineer
tarikbilla@gmail.com
+8801884414000
  • Reuse a hash in YAMLApril 17, 2024
  • Dockerfile: how to redirect the output of a RUN command to a variable?April 16, 2024
  • How to cd to a directory with spaces in the directory name?April 16, 2024
  • Maximum MIME type length when storing the type in a databaseApril 16, 2024
  • What is the difference between Unit, Integration, Regression and Acceptance Testing?April 16, 2024
© 2026 Tarik Billa