Skip to content Skip to sidebar Skip to footer

Thread Malfunction

I have this project, with 2 classes. activity_main has 2 buttons, button1 runs a thread and I want to stop it with button2, but it does not work, because while the thread is runnin

Solution 1:

To run a Thread instance in a separate thread, it's Thread#start(), not Thread#run(). Thread#run() will not create a new thread but just run run() in the current thread (which is UI Thread, this is why you get ANR).

Also it's better to implement Runnable than to extend Thread.

Post a Comment for "Thread Malfunction"