简体   繁体   中英

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

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM