0

In my android application in java, I am doing an http async request then I want to print the result in a TextView that is in a ScrollView.

This work fine when the result to print is short. But it can be very long and then the application is freezing for ~3-5 second.

I know this is because to much work is done on the main thread but is there a way to set the text of a TextView on a separeted thread ?

To illustrate this is my code in the onResponse of the httpRequest :

tView2.setText(requestName);
tView3.setText(message1);
tView4.setText(messag2);
tView4.setText(resultBody);
tView5.setText(message3);

If i just remove the line

tView4.setText(resultBody);

(where resultBody contains a long String) The UI does not freeze any more, and the other message are print almost instantly.

But when I let it the UI is freezing even before the print of the previous message so I can't even set a message of information preventing the user that can take some while (what I tried in my code, it's why there is 2 setText on the tView4)..

What I want is the simpliest solution to manage that. So an easy way to print a message of information to prevent the user would be good.

Thank you.

bloub
  • 510
  • 1
  • 4
  • 21
  • Please post your complete code – nishith kumar May 11 '17 at 13:36
  • I don't see the point. This code is run on the UI thread in the onResponse of a volley async request. If i process the request but comment the line tView4.setText(resultBody); the UI doe not freeze any more and the other message are shown instantly. – bloub May 11 '17 at 13:45
  • See http://stackoverflow.com/questions/17281625/textview-settext-with-very-long-string-blocks-ui-thread or use a WebView. – CoolMind May 11 '17 at 13:55
  • That what i was looking for, thank you. But the problem now is that the app lag when I scroll down since every time i scroll i update the current position of the scrolling. I deplace all the code that decide if yes or not I add some text to the view in an async task but even like that it lags. – bloub May 11 '17 at 14:58

0 Answers0