Home>

I am making a request for a site viaAsyncTask < Strin, Strin, String >and I get a JSON string from there, from which I take everything I need. In short, everything is as usual, a standard procedure. I haveRecycler View, which I need to fill with data that I received from another stream. When I try to do this, nothing happens. I later read that UI elements are not thread-safe. How can I fillRecycler Viewdata I am getting from another thread?

Please provide your code

Arty Morris2021-12-30 12:38:00

It's very simple: in onPostExecute () you pass new data to the adapter and call it one of the most suitable methods for you, notifyXXX (). The onPostExecute () method is called on the correct (UI) thread.

woesss2021-12-30 16:21:20
  • Answer # 1

    If in Java, then from the workflow to the main one you can go like this, try it -

    runOnUiThread (new Runnable () {
      @Override
      public void run () {
    //code for the main thread
     }
    

    });