i'm a beginner in android and have not much experience on java...
I have an Activity that creates an ALARM MANAGER
and starts alarmManager.setRepeating()
pointing to a Service.
This Service in onCreate set a partial wakelock to perform the entire execution of the code (the app is made for non user interaction an so the phone is always in standby).
All of this work perfect.
Sometimes the Service should not perform entire code, but exit before from execution. So i have used StopSelf
but i have some doubts:
onDestroy
function in Service has the code to delete the wakelock. Does StopSelf()
call it?
Anyway if i don't specify any function to terminate the service, after code execution when is it terminated?
So in my case, is better replace onDestroy()
instead of Stopself()
?
many thanx!
You should call stopSelf ()
to stop a service. After you call it, the Android Framework will call onDestroy()
method automatically.
Actually, these onXXX() methods(the prefix "on" implies that these methods are callbacks for the system) should be called by the system, not the developers. Read the SDK document for more details.
stopSelf()
is called before the Thread
finishes.
The Thread
runs to completion when stopSelf()
is called.
Service
is still destroyed at the point of the stopSelf()
call.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With