Found some people who just learned Android, and I was the same, on the Android thread will have a certain misunderstanding.
In Android, when you start a new thread, some people use the following methods:
New Handler (). Post (R);
But this does not open a new thread, but simply adds the current task to the main thread. If you want to open a new thread, you should use Handlerthread, using the following:
New Handlerthread (name); Thread.Start (); New Handler (Thread.getlooper ()). Post (R);
If you use more of this, you can encapsulate a static method that gets an object that performs tasks on a new thread:
/* * * Gets the handler object that runs on the new thread. * * @param name * thread names. * @return The handler object that is running on the new thread. */ Public Static Handler getnewhandlerinotherthread (String name) { new handlerthread (name); Thread.Start (); return New Handler (Thread.getlooper ()); }
The myth of the Android Open thread