Logo Icon Logo
A Crowd-sourced Cookbook on Writing Great Android® Apps
GitHub logo Twitter logo OReilly Book Cover Art

Returning a value from an Activity to the Service that started it

In Chapter: Inter/Intra-Application Communication
Author: Ian Darwin (ian@androidcookbook.com) 'idarwin'
Published? false
FormatLanguage: WikiFormat


Your Service starts an Activity, which does something. Naturally you want to feed this updated value back to the service, which will know what to do with it.


Use a Handler or a Broadcast Receiver.


Sadly, Android does not provide a mechanism explicitly for returning a value from the Activity to the Service, so you have to use other means. While Activity classes can use either startActivity() or startActivityForResult(), Service classes can not use the latter. Your choices include:

  1. Use a Handler class (see 921)
  2. Use a Broadcast Receiver (see 934)
  3. Use some other unsupported mechanism, and risk damage when the API changes.