Is there a way to do UI changes in a non-UI thread? Short question.
As such, the main thread is also sometimes called the UI thread. However, under special circumstances, an app's main thread might not be its UI thread; for more information, see Thread annotations. The system does not create a separate thread for each instance of a component.
Service runs in the main thread of its hosting process; the service does not create its own thread and does not run in a separate process unless you specify otherwise.
If you put long running work on the UI thread, you can get ANR errors. If you have multiple threads and put long running work on the non-UI threads, those non-UI threads can't inform the user of what is happening.
UI Thread and Main Thread are same only in Android. The Main thread, that is responsible for handling the UI events like Draw, Listen and receive the UI events. Ans also it is responsible for interact with running components of the UI toolkit for the corresponding application that belongs to.
Either use Handler or use below code
runOnUiThread(new Runnable()
{
@Override
public void run()
{
// Ui Stuff here
}
});
There are many way to do this, use AsyncTask or Threads. Short answer.
Hint: the UI stuff can be done in the pre-postExecute/runOnUiThread/Handler class
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With