In Android app, I am using NFC reader. There is a listener for that NFC reader in the app. When an NFC tag is read, it triggers the listener in the app. That listener is not in the main thread, but a worker thread.
When that event is called, I need to update the UI with the value. Since It's a worker thread, my code is like:
runOnUiThread(new Runnable() {
@Override
public void run() {
binding.nfc.setVisibility(View.VISIBLE);
binding.nfcProgressBar.setVisibility(View.VISIBLE);
}
});
Where binding is Data Binding the UI components into the View Models.
The problem is with Updating of UI components, even though those line of code inside run() is executed all times. Sometimes it gets updated and sometimes it doesn't.
The NFC will be read continuously in the same activity, the first time I read NFC after opening the app, it works, after that, it fluctuates.
Every time it goes through the runOnUiThread Runnable method but the UI only gets updated sometimes.
I am wondering if There is a problem with my code or runOnUiThread is like that only.
It's fluctuating.