Suppose I have a class Main (Activity). It displays main_layout.xml . I also have a class NotMain, in which there is a stopWorking () method that does

Thread t = new Thread(new Runnable() { public void run() { TimeUnit.SECONDS.sleep(4); String output = "Test"; } }); t.start(); 

From the main Main class, I call this method, which after execution must somehow send the output string back to the main stream, to Main , so that it assigns it to the TextView in main_layout.xml . How can this be realized?

Ps I can not give the full code of the program, it is too confused and great for everyone to see, but I can not figure out with this part of the program

    1 answer 1

    If you still want to use samopisny streams, look towards the post method on all descendants of the View (including TextView)

    • Can you use ready-made streams? I just have a task - to get the code of the html-page in one class and pass it on to another class - Yegor Gavrilov
    • one
      Such tasks can be solved using AsyncTask, if I understand correctly what you are talking about. In general, you can read here [Processes and Threads] [1] [1]:… - rasmisha
    • Could you give us an example of using or a piece of code? I just can’t find my case (or similar) in the documentation or in the tutorials and have a bad idea of ​​what to write and where - Yegor Gavrilov
    • can this example be suitable And what do you mean by transfer from one class to another? Just as a parameter or what? - rasmisha
    • I have 2 classes (file). From the first one, a request is sent to execute the second class method, which receives the html-code of the page and sends it back to the first class. But getting the html page requires loading it in a new stream, but from the new stream you cannot (as far as I understand) transfer data to the old streams only if you call another class method using Handlers. But it is still not clear how to convey what I received in another class and in another stream to the original class. - Yegor Gavrilov