I want to a start a Service with an Intent that contains a callback. How can I do that? I want to use startService(…), not the binding mechanism.
Share
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.
I would recommend to use a custom broadcast which will be sent by the service. You can register for that broadcast in your activity and catch that. That would be the standard solution for a service callback. You can’t put complex data (like references) in your intent, simple and primitive data only…
Custom Intents and Broadcasting with Receivers
Update based on comment
How to interpret this presentation then (slide 11, number in bottom left corner)?
In this case they’re using a service helper. I think they start the server with
startServiceto symbolize that the service should stay awake. AbindServicewould stop the service when the binding activity is destroyed. The service helper will callbindServiceanyway because it says10. Binder callback. So in the end the helper seems to be a bind wrapper for the requesting activity so the activities have not to deal with the whole service communication.That’s the way I would interpret it…