Because a process running a service is ranked higher than one with
background activities, an activity that initiates a long-running
operation might do well to start a service for that operation, rather
than simply spawn a thread — particularly if the operation will likely
outlast the activity. Examples of this are playing music in the
background and uploading a picture taken by the camera to a web site.
Using a service guarantees that the operation will have at least
"service process" priority, regardless of what happens to the activity.
As noted in the Broadcast receiver lifecycle section earlier, this is
the same reason that broadcast receivers should employ services rather
than simply put time-consuming operations in a thread.
只有service 的进程比只有分线程的process 优先级 高 持续时间有可能更长。
local service 和remote service 区别?适用场合?
最新推荐文章于 2023-05-10 16:04:11 发布
本文讨论了在Android应用中使用服务来进行长时间运行的操作的重要性。服务进程的优先级高于背景线程,确保即使在触发活动不再存在时,关键任务也能继续执行。文章通过播放背景音乐和上传图片到网站的例子说明了这一点,并强调了广播接收器也应该使用服务来处理耗时的任务。
3850

被折叠的 条评论
为什么被折叠?



