在 Android 中,当我在服务中创建一个 runnable 并运行它时,虽然我意识到它在自己的线程中运行,但这个线程是否以某种方式成为 UI 线程的一部分?换句话说,如果runnable执行的过程很长,会不会影响UI?
编辑:
private class SomeRunnable implements Runnable
{
@Override
public void run()
{
try
{
}
}
}
SomeRunnable runnable = new SomeRunnable();
(new Handler()).postDelayed(runnable, 1000);
最佳答案
文档:
A services runs in the same process as the application in which it is declared and in the main thread of that application,
不同线程:
Thread t = new Thread(new MyRunnable());
t.start();
UI/服务线程:
Handler h = new Handler();
h.post(new MyRunnable());
关于android - 服务中的可运行对象是否在 UI 线程上运行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14808640/