All:
I am studying code that has a handler that is declared and instantiated along with other instance variables:
public class SomeActivity extends Activity {
Handler handler = new Handler(); // What thread is this taking place on?
// rest of class omitted
}
so is it being instantiated on the UI thread? I hope so, because it is used to post a Runnable to a ProgressBar, and my understanding is that the ProgressBar should only be manipulated on the UI Thread.
The Android docs say that something created in onCreate() is:
An application’s activities run on the application’s UI thread. Once
the UI is instantiated, for example in the activity’s onCreate()
method, then all interactions with the UI must run in the UI thread.”
but this is happening before onCreate().
Thanks for any info,
Michael
Yes. A Handler will exist in the Thread where it is created. You are creating yours on the main / UI Thread, so it can access UI elements.
This won’t effect which Thread the Handler runs on.