今天学习的是Severice生命周期和启动方式
Severice的创建 继承Service
![](https://img-blog.csdnimg.cn/img_convert/1c90cdede3085d2b7b7aac0dccb8e162.png)
每一个都在AndroidManifest中注册
![](https://img-blog.csdnimg.cn/img_convert/8ded9243b76c831f0073f3aaad0e7090.png)
使用startService进行启动
在MainActive中绑定
public void start(View view) {
Intent intent = new Intent(this,MyService.class);
startService(intent);
}
![](https://img-blog.csdnimg.cn/img_convert/391b5a66e397912107d6c1fca478c5c9.png)
里面有onCreate创建方法
onStartCommand方法
onDestroy方法
onBind方法
![](https://img-blog.csdnimg.cn/img_convert/1fb5b777eeb971c166644e6e92a48c74.png)
解绑方法
![](https://img-blog.csdnimg.cn/img_convert/996f854ccc9e5bbc0071ae4c1b127ef6.png)
绑定方法
![](https://img-blog.csdnimg.cn/img_convert/50c7cb5738f03503f184596ebfdb49b8.png)
![](https://img-blog.csdnimg.cn/img_convert/0e2559bec5dfa3734c867c7a2fcff2fa.png)