Returning a value from an Activity to the Service that started it
In Chapter: Inter/Intra-Application Communication
Author: Ian Darwin (email@example.com) 'idarwin'
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:
- Use a Handler class (see 921)
- Use a Broadcast Receiver (see 934)
- Use some other unsupported mechanism, and risk damage when the API changes.