문제

I have an IntentService which queues up web service calls to be made. I pass an integer as an Extra with each Intent which defines the type of web service call to be made.

I'd like to create a situation where, if an Intent to perform a particular web service is passed to the IntentService and an Intent for that same web service already exists in the IntentService queue, the Intent is not processed. Ideally, I'd throw away the Intent, but I could also add an Extra to it that lets the code know to skip the Intent once it is handled. As Intents come in, I could keep track of which ones are in the queue in some object I add to the IntentService.

However, I don't see a place to intercept the Intent right when it is passed to the IntentService. As far as I can tell, I can only touch it when onHandleIntent is called and that would be too late.

Any ideas?

도움이 되었습니까?

해결책

Its not strictly speaking advisable, but I'd suggest something like this:

public int onStartCommand (Intent intent, int flags, int startId)
{
  // do your intent modification here
  //if(intentIsDuplicate(intent))

  // make sure you call the super class to ensure everything performs as expected
  return super.onStartCommand(intent, flags, startId);
}

Let me know if that works.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top