Stop A Service When Application Is In Background
I'm new to android and I am creating a MAC spoofing app. I have created an IntentService to spoof the MAC address in the app every 5 seconds and it is working fine. Then I created
Solution 1:
For some reason the service is not stopping when the app goes to background
It stopped long before your stopService()
call, as it stopped once onHandleIntent()
returned, milliseconds after it was created.
What is not stopping is your Timer
, which runs on a background thread and will continue running until you cancel it or your process terminates.
IMHO, this is an inappropriate use of IntentService
. If you want to control the lifespan, use a Service
, and stop background work in onDestroy()
.
Post a Comment for "Stop A Service When Application Is In Background"