📜  无法在未调用 Looper.prepare() 的线程 Thread[DefaultDispatcher-worker-1,5,main] 内创建处理程序 - 无论代码示例

📅  最后修改于: 2022-03-11 14:56:12.179000             🧑  作者: Mango

代码示例1
mHandler = new Handler(Looper.getMainLooper()) {
    @Override
    public void handleMessage(Message message) {
        // This is where you do your work in the UI thread.
        // Your worker tells you in the message what to do.
    }
};

void workerThread() {
    // And this is how you call it from the worker thread:
    Message message = mHandler.obtainMessage(command, parameter);
    message.sendToTarget();
}