This answer assumes that the Service in question runs in a different process:
Yes, it is possible. The general idea is that not only your Activity
binds the remote Service
through some AIDL defined interface, but it also implements additional AIDL interface which the Service
is aware of, and sets itself as a callback target of the remote Service
.
You'll have to have 2 AIDL files: the first one describes the interface of the Service
, and the second one describes the interface of the Activity
.
The implementation of such a scheme is very similar to "remote Service callbacks" described in this answer, though "callback" method would no longer be void
, but return the value you're interested in.
Design considerations:
The above scheme will allow you to get values from Activity
, but I don't think you should take this path. From the description of your use case, it looks that you only want to pass some value to the Service
when Activity
gets resumed. Since your Service
is bound anyway, you can simply add a method setSomeValue(int value)
to its AIDL definition and call this method from onServiceConnected()
callback.