开发者

Do I need a thread in a boot_completed and startForeground started service?

开发者 https://www.devze.com 2023-01-27 07:04 出处:网络
I\'m starting my service with the BOOT_COMPLETED broadcast and then bring it to the fron开发者_如何学Got with startForeground. Using it in a closed system, so it won\'t bother any other apps. Anyhow,

I'm starting my service with the BOOT_COMPLETED broadcast and then bring it to the fron开发者_如何学Got 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:

  1. 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?

  2. If I start a service with startForeground and I start a thread in that service, will the thread also be on foreground?

  3. Will every service/activity that I start from the service (that's on foreground) automatically also be on foreground?

Thanks!


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号