This is code taken and modified from a now depreciated library called DataDroid but it is relevant to what you are attempting to do.
private final class RequestReceiver extends ResultReceiver {
RequestReceiver() {
super(new Handler(Looper.getMainLooper()));
}
@Override
public void onReceiveResult(int resultCode, Bundle resultData) {
/*
* Depending on how you implement this either update activity from here
* or instantiate it with an interface that your activity implements and
* call that here.
*/
}
}
Create service with somethinglike this:
RequestReceiver requestReceiver = new RequestReceiver();
Intent i = new Intent(mContext, Service);
i.putExtra(RequestService.INTENT_EXTRA_RECEIVER, requestReceiver);
mContext.startService(i);
You could also just use the previously mentioned library and modify it to fit your current use case or use one of the many other similar libraries available.