I have a question which is related to this question that was asked by @mnish about a year ago.
Please have a look at his question and code. He implements a ServiceConnection() and passes it to bindService(). This follows the Local Service Sample in the Service documentation near the top.
I want to implement the Local Service Sample, so I am trying to add some details from @mnish question/answer. In ServiceConnection() @mnish has this line that confuses me:
mService = ILocService.Stub.asInterface(iservice);
I understand @mnish wrote this code, but does anybody have any idea what ILocService is and any idea how I might go about creating my own ILocService? Where is this construct documented and do I need it? Also where does the value for IBinder iservice come from?
He is probably using Android Interface Definition Language (AIDL)
http://developer.android.com/guide/components/aidl.html
Therefore he has to use a stub of the server side implementation like documented:
The iservice reference is coming from the onServiceConnected method which is called after binding the service to your activity. The call bindService gets passed the ServiceConnection which implements the onServiceConnected method.
You don’t need the “IRemoteService.Stub.asInterface(service)” when your implementation of the service is local, then you can just cast the service to you local service.
The local service sample does this in the service:
And this in the Activity in the ServiceConnection class: