Using an IntentService for local listening, but onDestroy is called right after onHandleIntent

I use IntentService to listen for GPS location updates, so it starts when the user leaves this activity. IS sends the location in the message to the activity handler.

The problem is that when the user clicks the โ€œstop trackingโ€ button, a notification of the status line with the inscription โ€œtracking ...โ€ still exists because it is created in the IntentService. So I redefined onDestory (), so I can call:

mNotificationManager.cancel(TRACKING); 

But the problem is that when I implement onDestroy (), it is called right after onHandleIntent. If I delete my redefinition code onDestroy (), it does not immediately get called and works fine, sending addresses back to the activity displayed on the screen.

Any ideas why onDestroy () is called immediately if I implement it, but not if I don't?

I'm pretty confused here.

Thanks everyone

Infinitifizz

+6
source share
1 answer

Ok, now I figured it out, I shouldn't have used IntentService, instead I used the Service and included all the functions in onStartCommand (), and now everything works.

Sorry for wasting your time: - /

Infinitifizz

+9
source

Source: https://habr.com/ru/post/887509/


All Articles