Service的onStartCommand中intent null point的问题

本文解析了Android系统中Service的START_NOT_STICKY属性作用,当进程被杀且没有新的启动Intent时,服务将不再重建。同时介绍了如何处理服务重启时Intent为空的情况。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

开始的时候很纳闷,为什么会这样了,然后就搜索了下,发现其实文档早就告诉我了,只不过英文差,没看仔细。。。


原文如下:

int START_NOT_STICKY Constant to return from onStartCommand(Intent, int, int): if this service's process is killed while it is started (after returning from onStartCommand(Intent, int, int)), and there are no new start intents to deliver to it, then take the service out of the started state and don't recreate until a future explicit call to Context.startService(Intent).
http://developer.android.com/reference/android/app/Service.html#START_STICKY

相信大家都是知道onStartCommand是有返回值的,这货真心是有用的,为的是告诉系统这后台服务要怎么存活着,其实英文不好的也可以慢慢看的,看着看着就懂了


本人遇到的问题,简单翻译过来就是,系统会重启app的服务,重启的时候intent就是空的,自己要做好判断。。。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值