0

I found this bug on with the following code:

(it.context.get() as? Activity)?.runOnUiThread(Runnable {
            it.weakRefIOnDataRefreshed.get()?.onDataRefreshed(refreshedItemList)
        })

The code above is inside a run method that runs in a non UI Thread. I want to call a method in fragment with the refreshedItemList as argument. I want to debug the onDataRefreshed method (which is inside a Fragment), and I'm putting inside this function a break point but nothing happens. I also put a Log method to make sure that the code is running and the Log method prints indeed. What may be the problem that the debugger doesn't stop on the line which I have marked?

DorVak
  • 297
  • 2
  • 9

1 Answers1

0

In your class where that background thread works define a Handler object and use post method to update UI e.g. (Java).

// Define handler object
Handler handler = new Handler(Looper.getMainLooper);
...
...

// Here ise where you want to update your UI
handler.post(() -> {
    // Your code with which you want to update the UI
}
Kozmotronik
  • 2,080
  • 3
  • 10
  • 25
  • What wrong the way I do it? And why the debugger ignores my request? – DorVak Dec 03 '20 at 15:04
  • It is all about the way you implement your code. It is hard to say something just by seeing 2 lines of code. I don't have any idea about your code, you tell the problem but didn't share enough code to analyze. – Kozmotronik Dec 03 '20 at 15:27
  • thanks suddenly after two restarts it works :) – DorVak Dec 03 '20 at 16:24