Service的onStartCommand()方法的返回值介绍

组件Service方法onStartCommand()的返回值为int类型,主要的作用是当Service进程被意外kill掉时,Service服务下一步要做哪些行为,主要有3种值。

START_STICKY:Service被异外终止时不调用onDestroy()回调,并且终止后自动重启Service服务,只执行Service对象的onCreate()生命周期方法。

START_NOT_STICKY:Service被异外终止时不调用onDestroy()回调,并且不自动重启服务。

START_REDELIVER_INTENT:Service被异外终止时不调用onDestroy()回调,并且终止后自动重启Service服务,还要执行Service对象的onCreate()和onStartCommand()生命周期方法,并且从Intent中能取到值。

猜你喜欢

转载自wenlively.iteye.com/blog/1740945
今日推荐