天天看点

Service的onStartCommand中intent null point的问题

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

原文如下:

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就是空的,自己要做好判断。。。