Wednesday, April 23, 2014

Service in the end not to call themselves Looper.prepare ()?


Wrote a Service, started a thread on the inside, then instantiates a Handler to process the message.
However, the runtime throws an exception that can not be created without calling Handler Looper.prepare () thread.

Then I call the () in the Service's onCreate Looper.prepare (), but was thrown, said one thread only one Looper.

Halo, in the end how should I do it?
<-! Main posts under Banner (D4) -><-! Posts under the main text (D5) ->
Reply:
The main thread itself is a Looper it has called prepare () you're going to open your own child thread calling prepare ()
Reply:
http://my.eoe.cn/lakeside/archive/15571.html
Reply:
Not to create a sub-thread inside Handler, but in the Service Handler created, but do not call Looper.prepare nor right, nor the call right.
Reply:
cited a floor a425801998 reply:
main thread itself is a Looper it has called prepare () you're going to open your own child thread calls prepare ()

In this case, the thread will always be running in the background ...
Reply:
thread you can not switch off the
Reply:
Brother you do not understand some of my questions:
I do not want to create a thread in the child inside Handler, but Handler created in the Service, but do not call Looper.prepare () is not right, the call is not right.
Reply:
After creating Looper loop it? Need to write Looper.loop ();
A Thread can only set a Looper, service default is the main thread in the Activity start time has loop up, it will throw an exception.
 
private static void prepare (boolean quitAllowed) {
if (sThreadLocal.get ()! = null) {
throw new RuntimeException ("Only one Looper may be created per thread");
}
sThreadLocal.set (new Looper (quitAllowed));
}

Reply:
Service to create a handler directly in oncreate where you can ah. Who knows how you write, no code no truth.
Reply:
I know, not the exception in the Service Handler created, but because I started a thread in the Service of the child, in order to be able to call the Service in this thread m_handler of m_handler.sendMessage (), put this m_handler passed to the child thread , recorded the handle in the child thread, the results of this sub-thread exception.
Reply:
In fact, because the child thread uses LocationManager, and created a Handler LocationManager

No comments:

Post a Comment