cuongptnk cuongptnk - 1 year ago 72
Android Question

Understand Bound Service Documentation

Refer to the example in this Bound Service documentation:

Binder is a class implementing the interface IBinder. However, in the example, I cannot understand why we use

IBinder mBinder
instead of
Binder mBinder
? Why make it more complicated with IBinder? And why do we need LocalBinder class for just to return the instance of LocalService?

Answer Source

You don't need to do it that way. If you want to store a LocalBinder, you can. If you want to return a new Binder instance for each client binding, you can. The only thing you need to do is return non-null if you want it to be possible to bind to you (if you want the service to only work via startService and not via bindService, you can just return null).

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download