How does the server expose the IBinder interface object?
How does the server expose IBinder interface objects:
Package com. example. mydownload; import android. app. service; import android. content. intent; import android. OS. binder; import android. OS. IBinder; import android. util. log; // method in the implementation interface public class MyService extends Service {// interface object IBinder mybBinder = new MyBinder (); class MyBinder extends Binder {public String helloWorld (String name) {return name ;}@ Overridepublic void onCreate () {Log. e ("log", "onCreate"); super. onCreate () ;}@ Overridepublic void onDestroy () {Log. e ("log", "onDestroy"); super. onDestroy () ;}@ Overridepublic int onStartCommand (Intent intent, int flags, int startId) {Log. e ("log", "onStartCommand"); return super. onStartCommand (intent, flags, startId) ;}@ Overridepublic IBinder onBind (Intent arg0) {return mybBinder ;}}
How does the client call methods in interface objects and write them at night.
Bindservice cannot be bound to a service
A binding Service is a component that implements a class Service and allows other applications to bind and interact with it. To provide a binding service, you must implement the onBind () method. This method returns an IBinder object, which is an interface that defines the client to interact with the service.
When multiple clients connect to the Service at the same time, the system only calls your onBind () method when the first client connects and returns an IBinder object, the system returns the same IBinder object when other clients connect, instead of calling onBind ().
This is the basic principle of binding a Service.
Public static IBinder getService (String name) {} How to call this method? I called getService and said that I lack IBinder.
IBInder is an interface
After defining the class name of this function, add: IBinder
For example
Public class A: IBinder
{
Public static getService (String name ){}
}