公告
财富商城
积分规则
提问
发文
2019-01-25 12:08发布
甜甜的少女心
When a service has been killed, how to restart it automatically?
sometimes without even calling onDestroy()
onDestroy()
If you have your service killed, the system will try to restart it later. Read more.
Overrides the onStartCommand() and give START_STICKY or START_REDELIVER_INTENT (depends on your needs) as the return value. The system will then make sure to restart your service until you explicitly stop the service.
onStartCommand()
START_STICKY
START_REDELIVER_INTENT
http://developer.android.com/reference/android/app/Service.html#START_REDELIVER_INTENT
http://developer.android.com/reference/android/app/Service.html#START_STICKY
I inherited an IntentService, so I had to be gentle. It worked for me when I overrode onStartCommand() but
public int onStartCommand(Intent intent, int flags, int startId) { super.onStartCommand(intent, flags, startId); return START_STICKY; }
That is, let the parent do what it should and return START_STICKY.
最多设置5个标签!
If you have your service killed, the system will try to restart it later. Read more.
Overrides the
onStartCommand()
and giveSTART_STICKY
orSTART_REDELIVER_INTENT
(depends on your needs) as the return value. The system will then make sure to restart your service until you explicitly stop the service.http://developer.android.com/reference/android/app/Service.html#START_REDELIVER_INTENT
http://developer.android.com/reference/android/app/Service.html#START_STICKY
I inherited an IntentService, so I had to be gentle. It worked for me when I overrode onStartCommand() but
That is, let the parent do what it should and return START_STICKY.