java.lang.RuntimeException: Can't create handler inside thread that has not called Looper.prepare()
这时今天遇到的第二个错误。
原因是非主线程中没有创建Looper对象,需要先调用Looper.prepare()启用Looper。
解决办法是在线程的开始跟结束间调用Looper.prepare(); 跟Looper.loop();
如:
ExecutorService cachedThreadPool = Executors.newCachedThreadPool();
cachedThreadPool.execute(new Runnable() {
@Override
public void run() {
Looper.prepare();
***********
Looper.loop();
}
});
注意:一个线程只能有一个Looper