How to return JobService results?

I play a little with Android and write a small application with activity and service. The action starts the service at the click of a button, and it should retrieve some data from the URI and return it as a result. Sometimes the data is not available or does not meet the criteria, and then the service must repeat every X minutes, even if the activity is in the background.

I implemented the connection between activity and service through Intentand ResultReceiver(provided in the kit). When implementing the service, I wanted to use a new component JobScheduler, but then I saw that it can only accept PersistableBundle, which the object Parcelable( ResultReceiver) cannot add , but only the main types.

I want the service to schedule a task that will run when the network is available, and every X minutes to check the data. As soon as he receives it, I want the data to be returned to the service so that he can decide if this is acceptable or we need to try again. If the service accepts the data, it will put it back into action with ResultsReceiver.

I cannot use ResultsReceiverwith JobService, and since I am not creating an instance JobService(done JobInfo.Builder), I cannot pass it a reference to the callback object.

How can I communicate between a scheduled task and the service that called it?

Sorry if this is trivial, I am not familiar with Android.

Thank!

+4
source share
1

, ?

, . , , , . , JobScheduler, - , . , .

(greenrobot EventBus , LocalBroadcastManager ), , , . ( ) . , , , " ", , JobService " ", .

+5

All Articles