首页 > 移动平台 > 详细

android 基础一 <Service>

时间:2019-09-07 00:08:45      阅读:135      评论:0      收藏:0      [点我收藏+]
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>

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

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!