Service

来源:互联网 发布:nginx pathinfo配置 编辑:程序博客网 时间:2024/06/02 12:32

1. Service被设计成长期运行的组件,相反生命周期短并且随时被停止运行的组件包括Activities, content providers, 和 intent receivers。

      Activities, content providers, and intent receivers are all short-lived and can be shut down at any time. Services, on the other hand, are designed to keep running, if needed, independent of any activity.

 

2.应用的场合

     You might use a service for checking for updates to an RSS feed, or to play back music even if the controlling activity is no longer operating.playing music even if the "player" activity gets garbage-collected, polling the Internet for RSS/Atom feed updates, and maintaining an online chat connection even if the chat client loses focus due to an incoming phone call.

 

3.IPC inter-process communication

 

4.注意的问题

Service可能会长期占用系统资源,会引发电池不足的现象。

 

5.创建Service

(1)定义子类继承Service

(2)重写onCreate()/onStart()/onDestroy()...