I have a Service that can be stopped in multiple ways. Whenever I call stopService(Intent), I pass an intent with some extras. How do you retrieve those extras?
Thanks.
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
You need to override
onStartCommand()in yourServicethis is how you get a reference to the incoming intent fromstartService.In this case you would have a special action in your intent to tell the service to stop itself. You add extras to this intend which can be read in the
onStartCommand()method.Sample Code
Explanation
Every time you call
context.startService(Intent)onStartCommand()will be called. If the service is already running a new service isn’t created butonStartCommandis still called. This is how you can get a new intent with extras to a running service.