android 中使用service主要是作一些费时的,影响用户体验的操作。但是service实际上也是运行在主线程中,你如果不再serivce中新作线程来进行以上的费时操作的话,一样会影响用户的操作。
这个地方一直很疑惑?既然都是作thread来作费时的操作为什么还要作service呢。
参阅了guide上的这篇文章《Processes and Threads》,明白了android 对老进程的销毁原则:service的重要度要大于activity,因此对于一些运行在后台的线程,应该声明在service中,以避免被系统销毁。
以下是原文中的一段解释:
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.
分享到:
相关推荐
3. 串口服务器设备连接 9 5. IOT 工控云邮件报警功能 35 7. 远程升级 41 1. IOTSERVICE 介绍 2. IOTSERVICE 工具安
AccessibilityService的使用方式介绍及使用细节,适合初学者。
ServiceNow 平台基础说明和使用指南,希望对大家有所帮助
android service使用详解,初步了解service的使用,关注博客 http://himici.com/
Android Service使用,包括Start Service和bind Service启动方式。Service与Acvitity互相传递数据
Java Service Wrapper使用说明
演示了Service的各种使用方式,应可供初学者学习。
Java Service Wrapper使用总结,将java应用发布为可安装的服务
android service使用的小demo 包括startService stopService bindService unbindService 两种开启、关闭service的小demo
service的使用,以及在绑定的service中发送通知
SpringBoot 使用Java Service Wrapper 部署Windows服务
Linux中jar使用service启动脚本
Service 是一个可以在后台执行长时间运行操作而不提供用户界面的应用组件。服务可由其他应用组件启动,而且即使用户切换到其他应用,服务仍将在后台继续运行。...只要满足这两个情况之一,都可以考虑使用Service。
Unisphere Service Manager(USM)是一个基于Java的桌面应用程序,是EMC VNX中端产品系列维护的重要工具之一,主要用途是:升级、安装和维护存储系统的硬件和软件,以前的软件叫做 Navisphere Service Taskbar,简称...
Service 的基础使用方法 ,非常时候初学者。
Service端和Client端的完整代码和详细注释,详细讲解了RemoteService的使用以及注意点。
使用AIDL实现Service与Client绑定后的双向调用,Client在绑定Service时传入自己的Binder ,Service使用这个Binder实现调用Client的方法
使用ReportingService与CrystalReport开发企业报表
oracle service bus 12C 使用手册,截图全齐,只要跟着步骤一步一步走,即可成功。
使用Android实现的带进度条的播放器,音乐播放在Service中实现播放、暂停、继续和停止,但是停止和进度条的关联还有些问题,有待改进。