Infiniti Fizz
Infiniti Fizz

Reputation: 1726

Using IntentService for Location listening but onDestroy called immediately after onHandleIntent

I am using an IntentService to listen for GPS location updates so it'll run when the user leaves the activity. The IS sends the Location in a message to the activity's handler.

The problem is, when the user hits the "stop tracking" button, the status bar notification saying "tracking..." is still there because it is created in the IntentService. Therefore I overrided onDestory() so I can call:

mNotificationManager.cancel(TRACKING);

But the problem is that when I implement onDestroy(), it is called immediately after onHandleIntent. If I delete my override onDestroy() code then it isn't called immediately and runs fine, sending locations back to the activity to be displayed on-screen.

Any ideas why onDestroy() is getting called immediately if I implement it but not if I dont?

I'm pretty confused here.

Thanks all,

Infinitifizz

Upvotes: 6

Views: 1167

Answers (1)

Infiniti Fizz
Infiniti Fizz

Reputation: 1726

Okay I've sorted it out now, I shouldn't have been using an IntentService, used a Service instead and put all the functionality into onStartCommand() and now everything works.

Sorry everyone for wasting your time :-/

Infinitifizz

Upvotes: 9

Related Questions