I initialize and run a new thread in onCreate()
in MainActivity
@Override
protected void onCreate(Bundle savedInstanceState) {
// ... code
// New thread
new Thread(){
@Override
public void run(){
// Output is 'TAG: main'
Log.v("TAG",Thread.currentThread().getName());
}
}.run();
}
Why is the output of this line TAG: main
?
// Output is 'TAG: main'
Log.v("TAG",Thread.currentThread().getName());
Isn't this thread supposed to be a new thread?
If I stick an infinite while
loop into the thread, my app locks up, indicating that this new thread is indeed the main thread.
@Override
protected void onCreate(Bundle savedInstanceState) {
// ... code
// New thread
new Thread(){
@Override
public void run(){
// Output is 'TAG: main'
Log.v("TAG",Thread.currentThread().getName());
// Locks up the main thread apparently
while(true) {}
}
}.run();
}
I just don't get. Am I not creating a new thread and why?