Skip to content Skip to sidebar Skip to footer

Does Binder Have To Be An Inner Class?

I am reading upon Android Bound service, http://developer.android.com/guide/components/bound-services.html public class LocalService extends Service { // Binder given to clients pr

Solution 1:

It is an inner class so you can return the outer Service instance easily. You could als make it an external class:

publicclassLocalBinderextendsBinder {

  privatefinal LocalService mLocalService;

  publicLocalBinder(final LocalService service) {
    mLocalService = service;
  }

  LocalService getService() {
    return mLocalService;
  }
}

Using an inner class saves you from the trouble of creating a field and a constructor.

Post a Comment for "Does Binder Have To Be An Inner Class?"