我需要在 boot_completed 和 startForeground 启动的服务中有一个线程吗?
我用 BOOT_COMPLETED 广播启动我的服务,然后用 startForeground 将其带到前面。在封闭系统中使用它,因此不会打扰任何其他应用程序。无论如何,我有三个非常相似的问题:-),它们是:
我通常在我的服务中创建一个线程,但在这种情况下我需要这样做吗?哪个线程阻止了它在启动时启动的罪孽? UI 线程?
如果我使用 startForeground 启动一个服务,并在该服务中启动一个线程,该线程也会在前台吗?
我从服务(位于前台)启动的每个服务/活动是否也会自动位于前台?
谢谢!
I'm starting my service with the BOOT_COMPLETED broadcast and then bring it to the front with startForeground. Using it in a closed system, so it won't bother any other apps. Anyhow, I have three questions that are pretty similar to each other :-) , they are:
I usually make a thread inside my services, but do I need to do that in this case? Which thread is it blocking sins it's starting at boot-up? The UI-thread?
If I start a service with startForeground and I start a thread in that service, will the thread also be on foreground?
Will every service/activity that I start from the service (that's on foreground) automatically also be on foreground?
Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
1.) 活动和服务始终在 UI 线程中运行。
2.) 线程没有前台或后台的概念。它们与您的活动无关,而是与您的流程相关。
3.) 你认为前景意味着什么?所有这些都使得 Android 在内存不足时保持活动的优先级稍高。
1.) Activities and services ALWAYS run in the UI thread.
2.) Threads have no notion of foreground or background. They're not tied to your activity, they're tied to your process.
3.) What do you think foreground means? All that does it make it a slightly higher priority for android to keep alive if it runs out of memory.