I have an Activity that uses fragments. These fragments may come and go, based on the users interactions. Many of these fragments launch jobs to an IntentService, which get to run async this way. How should the IntentService report back the results of these jobs?
The fragment that started the job may of may not be present. If a job finishes and the starting fragment is currently active, then it should get notified about this, and act accordingly. If it's not, then no action is needed.
I've thought about using broadcast intents and BroadcastReceiver components, but fragments can't register receivers, only activities.
What solution would you suggest?
I noticed the same problem in IOSched App (Google I/O App for Android).
They created DetachableResultReceiver, which extends SDK class ResultReciever.
And they easily use it in Fragments.
Receiver:
Activity and Fragment: