I have a background service in my android application.In which a thread listening recent tasks running frequently.My service overrides both onCreate()
and onS
Android stops service when memory needs. You can use
@Override
public int onStartCommand(Intent intent, int flags, int startId) {
try {
if(intent != null){
//......
}
} catch (Throwable e) {
}
return START_REDELIVER_INTENT;
}
START_REDELIVER_INTENT can be used.if this service's process is killed while it is started (after returning from onStartCommand(Intent, int, int))
, then it will be scheduled for a restart and the last delivered Intent re-delivered to it again via onStartCommand(Intent, int, int)
.