Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

like image 625
Infiniti Fizz Avatar asked May 07 '11 10:05

Infiniti Fizz


1 Answers

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

like image 108
Infiniti Fizz Avatar answered Oct 16 '22 21:10

Infiniti Fizz