cuongptnk cuongptnk - 2 months ago 15
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?


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).