What is the best way to display something like logs on activations? You press the button, an http request is executed and its execution log is shown on the activation in real time. Sort of:

Соединение...Ок Посыл запроса...Ок Получение ответа...Ок 

That is, as in the console.

What control should I use? How to do this so that the GUI does not hang, that is, simultaneously with the sending of the request, a log was written.

  • ListView , no? The request can only work in parallel, in a separate stream, since working with the network in the main stream in Android is prohibited. - Vladyslav Matviienko
  • @metalurgus, isn't a simple TextView with "\ n" appropriate? - Oskar K.
  • one
    no, if the log is large enough, your application with OOM will drop due to the TextView of 10000x1080 in size when it is rendered. You try to attach just for example TextView in ScrollView , and insert into it, for example, the first volume War and Peace , and see what happens - Vladyslav Matviienko
  • there will not be many, I think, lines 20, even 50. well, even 500, that is, such "action - status" 500 times. and all - Oskar K.
  • So do with TextView , why are you asking? - Vladyslav Matviienko

2 answers 2

The problem is that network operations need to be performed in another thread, but you cannot update the Activity from another thread, and all because these operations are performed strictly in the main thread, so that you can do this you can inherit your AsynkTask and perform it in the method doInBackground () basic network operation, then in the onProgressUpdate () method, you can get data from the doInBackground () method and update the UI, for this you need to call publishProgress () method in doInBackground () , and return the value in the doInBackground () method from get it in the onPostExecute () method, which can also update the Activity, read here

    You can do it in different ways, but the simplest is ProgressDialog and AsyncTask . Google in this direction

    • I also need to map this to activity. - Oskar K.
    • The person wrote you everything correctly, in AyncTask you can also update Activity. - BORSHEVIK
    • @BORSHEVIK, I know, but that's not what I'm asking right now. What is the control to display the text logs? - Oskar K.
    • TextView does not suit you? - BORSHEVIK
    • one
      Then I tell you what is appropriate if you are going to do as you indicated in your question - BORSHEVIK