Android 애플리케이션이 있습니다. 하나 개의 활동에서 나는이 같은 서비스를 시작 다음과 같이IntentService STICKY가 파괴되었지만 서비스가 Android 2.3.4에서 로깅 데이터를 유지합니다.
Intent startIntent = new Intent(_context, HandlingService.class);
_context.startService(startIntent);
HandlingService가 정의 :
HandlingService 내부 그리고public class HandlingService extends IntentService
나는이 있습니다
@Override
public int onStartCommand(Intent intent, int flags, int startId) {
super.onStartCommand(intent, startId, startId);
Log.v(ApplicationName,"HandlingService.onStartCommand");
if ((flags & START_FLAG_RETRY) == 0){
Log.v(ApplicationName,"Service is restarting");
}
return START_STICKY;
}
이를 :
@Override
protected void onHandleIntent(Intent sourceIntent) {
Log.v(ApplicationName, "HandlingService.onHandleIntent");
sendSomething();
}
그리고 마지막으로 : 나는 HandlingService를 참조
Intent stopIntent = new Intent(CallingActivity.this, HandlingService.class);
CallingActivity.this.stopService(stopIntent);
:
protected void sendSomething() {
while (numberOfTry > 0) {
numberOfTry++;
Log.v(ApplicationName,"HandlingService.sending Something. Try# " + numberOfTry);
}
}
numberOfTry 내가이 부르는 취소 버튼을 클릭 서비스를 시작하는 활동에서 그런 1.
에서 시작 .OnDestroy가 호출되었지만 "HandlingService.sending Something"으로 로그를 계속 볼 수 있습니다. # "과 증가 숫자를 시도
이질문 :.?!. 그것이 내가 이미 stopService하기 위해 호출을 중지하면 살아 유지하는 이유
감사를 미리 기예르모에
하지만 OnStartCommand를 재정의하지 않으면 어떻게하면 어떨까요? 왜 그들이 그것을 오버라이드 할 수있게 만들지 만 문서에서는 "하지 마라"??? – polonskyg
'IntentService'는 자체 시작/중지 의미론을 가지고 있습니다. 작업자 스레드를 시작하고 대기열에서 수행 한 작업을 처리하고 완료되면 자체 작업을 중지합니다. 어떤 것도 무시할 필요가 없습니다. 문서화 된대로 작동합니다.작동 방식이 마음에 들지 않는다면 서비스를 확장하는 자체 서비스를 만들면됩니다. 'IntentService'가 이미 제공하고있는 시작/중지 의미는 무엇이 잘못 되었습니까? 당신이하려고하는 것은'IntentService'의 기본 행동으로 작동하지 않는 것입니까? –
조건에 도달 할 때까지 서비스가 계속 실행되어야하며 한 번만 실행하고 싶지 않습니다. – polonskyg