首页 > 系统 > Android > 正文

Android Service自启动注意事项分析

2019-10-24 20:18:48
字体:
来源:转载
供稿:网友
这篇文章主要介绍了Android Service自启动注意事项,结合实例分析了Android Service自启动过程中属性设置的相关技巧,需要的朋友可以参考下
 

本文实例分析了Android Service自启动注意事项。分享给大家供大家参考,具体如下:

@Overridepublic void onStart(Intent intent, int startId) {    super.onStart(intent, startId);    if(intent == null)      return;}@Overridepublic void onDestroy() {    super.onDestroy();    Intent intent = new Intent(SensorService.this, SensorService.class);    startService(intent);}@Overridepublic int onStartCommand(Intent intent, int flags, int startId) {//    flags = Service.START_STICKY;    flags = Service.START_REDELIVER_INTENT;    return super.onStartCommand(intent, flags, startId);}

PS重点就在这个 flags ,开始时用Service.START_STICKY; Service 经常会自动FC查了好久才发现再次自启动时候onStart里intent为null,改为flags = Service.START_REDELIVER_INTENT;就可以了。



注:相关教程知识阅读请移步到Android开发频道。
发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表