fhucho
fhucho

Reputation: 34560

How can I put a callback into an Intent?

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.

Upvotes: 2

Views: 2363

Answers (1)

Knickedi
Knickedi

Reputation: 8787

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 startService to symbolize that the service should stay awake. A bindService would stop the service when the binding activity is destroyed. The service helper will call bindService anyway because it says 10. 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...

Upvotes: 3

Related Questions