Thierry Ybt
Thierry Ybt

Reputation: 171

Android: pass data to a service

I'm actually working on an android app based on a background service sharing data with activities.

I was wondering If it's better to call bindService so that activities can call service's methods or if it's better to use sendBroadcast from the Activity and registerReceiver from the service.

Both work, but which one is recommended?

Furthermore, my service instanciates classes handling Localisation, sensors... Those classes also need to pass data with the service. Same question should I better use bindservice or sendBroadcast from these classes to communicate with my service?

Thanks.

Upvotes: 1

Views: 510

Answers (1)

ngesh
ngesh

Reputation: 13501

If at all if you want to pass data then use BroadcastReciever because its OnRecieve method expects an Intent as arguemnt.. So you can pass your data through intent using intent.putxxxxx().. and again you will find this Advantageous when you want do some periodic checking or invoke some actions etc..

Upvotes: 1

Related Questions