为了能够在我的应用程序/Activity 和本地服务之间编写“漂亮”的代码,我需要了解一些基本的 Android 概念:
我想知道我的应用程序(如在我的 Activity 中)和我的本地服务是否共享一个线程。 IE。当 Activity 和本地服务执行排队的任务时,这些任务是交错在一个线程中从而共享线程还是服务有自己的线程?
此外,如果本地服务与 Activity 共享线程并且本地服务直接调用(通过回调)其中一个 Activity (即没有发布消息)是 Activity 线程“暂停”或者执行无论如何,该特定功能排队等待稍后执行?
/亨里克
最佳答案
Like activities and the other components, services run in the main thread of the application process. So that they won't block other components or the user interface, they often spawn another thread for time-consuming tasks (like music playback). See Processes and Threads, later.
现在,如果该服务是一个单独的应用程序,那就是另一回事了..
也来自 Application Fundamentals :
In many ways, each Android application lives in its own world:
- By default, every application runs in its own Linux process....
关于android - 我的本地服务会产生另一个线程吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3112944/