我知道附加到主线程的处理程序在主线程上运行。
final Handler handler = new Handler(Looper.getMainLooper());
handler.postDelayed(new Runnable() {
@Override
public void run() {
}, DELAY_MS);
上面的 run 方法实际上是在不同的后台线程上执行的。
最佳答案
不,这只会在MainThread
上执行。
为什么? 因为您正在创建的 Runnable 已在 Loopers MessageQueue 中排队(可以包含 Runnable 或 other things ),并将按顺序处理。如果你想更深入地了解已经有a great question about the Looper asked
关于java - 匿名可运行实现并将其发布到处理程序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55959958/