A toast was used in the test service to print the log.
Prompt cannot call Looper.prepare ()
After adding, the code executes normally.
Looper.prepare (); Toast.maketext (Getapplicationcontext (), "Services Thread", Toast.length_long). Show () Looper.loop ();
But then there was another toast, and then there was an error stating that each thread could have only one looper
caused by:java.lang.RuntimeException:Only one Looper may be created per thread
To view the data, prepared will create a looper.
So the other place no longer needs to be called again.
//Looper public static final void Prepare () { if (Sthreadlocal.get () != null) { throw new RuntimeException ("Only one looper may be created per thread"); } sthreadlocal.set (New looper ()); //Create a looper } in the current thread Private looper () { mQueue = new MessageQueue (); //the key here, the creation of Looper has done nothing. is actually creating a message queue mRun = true; mthread = thread.currentthread (); &nbsP;} looper public static final void prepare () { if (Sthreadlocal.get () != null) { throw new runtimeexception (" Only one looper may be created per thread "); } sthreadlocal.set (New Looper ()); //Create a Looper } private looper () in the current thread { mqueue = new messagequeue (); //the key here, Create what Looper have done. is actually creating a message queue mRun = true; mthread = thread.currentthread (); }
Android Looper update UI in non-UI threads