码迷,mamicode.com
首页 > 移动开发 > 详细

android 基础一 <Service>

时间:2019-09-06 22:46:11      阅读:111      评论:0      收藏:0      [点我收藏+]

标签:comm   div   and   port   create   基础   span   enabled   执行流程   

1. 创建一个service
public class MyService extends Service {}
2.在清单中申明service
<application>
    <service
        android:name=".MyService"
        android:enabled="true"
        android:exported="true">
    </service>
</application>
3.调用service
Intent intent=new Intent(this,MyService.class);
this.startService(intent);
4.停止service
this.stopService(intent);或者 stopSelf
 
执行流程:
onCreate() //启动服务的时候执行,只执行一次
onStartCommand(Intent intent, int flags, int startId) //每次调用startService
onDestroy() //调用stoService 执行

android 基础一 <Service>

标签:comm   div   and   port   create   基础   span   enabled   执行流程   

原文地址:https://www.cnblogs.com/jtzp007/p/11478540.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!