Android Service系列(五)service的结束

If a component starts the service by calling startService() (which results in a call to onStartCommand()), the service continues to run until it stops itself with stopSelf() or another component stops it by calling stopService().

翻译:startService 要 stopSelf或者stopService才能终结

If a component calls bindService() to create the service and onStartCommand() is not called, the service runs only as long as the component is bound to it. After the service is unbound from all of its clients, the system destroys it.

翻译:bindService 要组件全部解绑后才会终结

-----------------------------------------------------------------------------------------------------------

The Android system stops a service only when memory is low and it must recover system resources for the activity that has user focus.

低内存的时候会停止service

If the service is bound to an activity that has user focus, it's less likely to be killed;

bound到有焦点的activity的service很少被杀

if the service is declared to run in the foreground, it's rarely killed.

前台service很少被杀

If the service is started and is long-running, the system lowers its position in the list of background tasks over time, and the service becomes highly susceptible to killing—if your service is started, you must design it to gracefully handle restarts by the system.

后台service随着时间推移变得更加可能被杀

If the system kills your service, it restarts it as soon as resources become available, but this also depends on the value that you return from onStartCommand(). For more information about when the system might destroy a service, see the Processes and Threading document.

service被杀后会重启,但是取决于onStartCommand的返回值。

In the following sections, you'll see how you can create the startService() and bindService() service methods, as well as how to use them from other application components.

下面讲startService和bindService这两个方法

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值