Service

来源:互联网 发布:ubuntu 编辑:程序博客网 时间:2024/04/30 08:10

service能被启动with Context.startService() and Context.bindService().

像其他的APP对象,他也执行在主线程中。这意味着开新线程对于耗CPU的

 

onCreate() onstart后,SERVICE将停在在这里直到  Context.stopService() or stopSelf() is called

无论掉多少次 Context.startService().如果SERVICE已经启动,那么只有ONSTART接受调用。而且停止只会有一次通过.stopService() or stopSelf()

 

 Context.bindService() 也可以得到SERVICE,如果没有创建,这个SERVICE将调用ONCREATE,但是不将调用ONSTART

 

Process Lifecycle

如果SERVICE已经被启动,他的进程将比可视进程差点,但是比不可视的重要

如果一个客户绑定到了这个SERVICE,那么这个SERVICE的进程至少和客户同等重要,

也就是说,如果客户是可视的,这个SERVICE自己也被考虑为可视的。

A started service can use the startForeground(int, Notification) API to put the service in a foreground state

原创粉丝点击