您的位置:首页 > 移动开发 > Android开发

Android的Activity启动长时间的操作开启一个Service比开启一个线程好

2011-07-05 00:53 561 查看
Because a process running a service is ranked higher than a process with background activities, an activity that initiates a long-running operation might do well to start a service for that operation, rather than simply create a worker thread—particularly if the operation will likely outlast the activity. For example, an activity that's uploading a picture to a web site should start a service to perform the upload so that the upload can continue in the background even if the user leaves the activity. Using a service guarantees that the operation will have at least "service process" priority, regardless of what happens to the activity. This is the same reason that broadcast receivers should employ services rather than simply put time-consuming operations in a thread.
Android的Activity启动长时间的操作开启一个Service比开启一个线程好,因为启动一个Service,他的进程级别为服务进程,优先级大于一个后台进程,被系统回收的概率低。

Android进程优先级:前台进程,可见进程,服务进程,后台进程,空进程。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: