How does the server expose the IBinder interface object?

Source: Internet
Author: User

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 ){}
}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.