UI not updating after API Call
Hi All,
I’m facing an issue in my Android app where the UI is not updating even though the API call returns the correct data. I’m using ViewModel + LiveData. The LiveData value updates (I confirmed in logs), but the Fragment UI doesn’t refresh unless I rotate the device or navigate back and forth. I already tried observe (viewLifecycleOwner) and ensured I’m not using the Activity as the lifecycle owner. Still no change.
Has anyone faced this before? Any idea what might be causing the observer not to trigger?
I’m facing an issue in my Android app where the UI is not updating even though the API call returns the correct data. I’m using ViewModel + LiveData. The LiveData value updates (I confirmed in logs), but the Fragment UI doesn’t refresh unless I rotate the device or navigate back and forth. I already tried observe (viewLifecycleOwner) and ensured I’m not using the Activity as the lifecycle owner. Still no change.
Has anyone faced this before? Any idea what might be causing the observer not to trigger?
-
juliagarcia
- Reviewer
- Posts:5
- Joined:Sun Nov 15, 2026 3:50 am
Re: UI not updating after API Call
First check whether the observer callback itself is actually running: add a log inside observe(), not just where you set the LiveData value. If it runs, the data layer is fine and the problem is likely in how the fragment applies the value to its binding/views or adapter. If it does not run, verify the fragment observes the same ViewModel instance it updates, and that observation is registered in onViewCreated using viewLifecycleOwner. Also confirm setValue() is called on the main thread; use postValue() only when needed.
-
SlateCedar
- Posts:3
- Joined:Sun Nov 15, 2026 8:24 am
Re: UI not updating after API Call
If the Fragment only shows the updated data after a screen rotation, double-check that you aren't instantiating a second ViewModel instance inside the Fragment or mutating a list in-place without passing a new list reference to ListAdapter.submitList(). Also make sure the API callback uses postValue() when updating MutableLiveData from a background thread.
Return to “Questions about Android”
Who is online
Users browsing this forum: No registered users and 2 guests