You should look at creating your own ResultReceiver subclass in your activity. ResultReceiver implements Parcelable so can be passed from your Activity to your Service as an extra on the Intent.
You’ll need to do something like this:
-
Implement a subclass of
ResultReceiverwithin your activity class. The key method to implement isonReceiveResult(). This method provides you a withBundleof result data which can be used to pass whatever information you are retrieving in yourService. Simply unpack the data you need and use it to update your activity. -
In your activity, create a new instance of your custom
ResultReceiverand add it to theIntentyou use to start your service. -
In your
Service‘sonStartCommand()method, retrieve theResultReceiverpassed in on theIntentand store it in a local member variable. -
Once your
Servicecompletes its work, have it callsend()on the ResultReceiver passing whatever data you want to send back to the activity in aBundle.
This is a pretty effective pattern and means you’re not storing data in nasty static variables.