I'm playing a bit with Android and writing a small app with an activity and a service. The activity starts the service on button click and it should fetch some data from a URI and return it as a result. Sometimes, data is not available or doesn't meet a criteria, and then the service should retry every X minutes even if the activity is in the background.
I've implemented the communication between the activity and the service via Intent
and ResultReceiver
(passed in the bundle). When implementing the service, I wanted to use the new JobScheduler
component but then saw it can only accept a PersistableBundle
which can't add a Parcelable
object (ResultReceiver
) but only the basic types.
I want the service to schedule a job that will run when network is available and every X minutes to check for data. Once it gets it, I want the data to be returned to the service so it can decide if it's acceptable or we need to retry again. If the service accepts the data, it will return it to the activity via the ResultsReceiver
.
I can't use ResultsReceiver
with the JobService
, and it since I don't construct the JobService
instance (done by the JobInfo.Builder
), I can't pass it a reference to a callback object.
How can I communicate between a scheduled job and the service that invoked it?
Sorry if it's trivial, I'm not familiar with Android..
Thanks!