宾德必须是内心阶级吗?

时间:2015-10-09 06:05:15

标签: android android-service android-service-binding

我正在阅读Android绑定服务,http://developer.android.com/guide/components/bound-services.html

    <div ng-controller="itemController">
<form ng-submit="addItem()">
    <label>Name:</label><input type="text" name="name" value="" ng-model="newitem.name" placeholder="Item Name">
    <label>Model No:</label><input type="text" name="model" value="" ng-model="newitem.model" placeholder="Model Number">
    <label>Size:</label><input type="text" name="size" value="" ng-model="newitem.size" placeholder="Item Size">
    <label>Colour:</label><input type="text" name="color" value="" ng-model="newitem.color" placeholder="Item Colour">
    <br>
    <label>Description:</label><textarea cols="30" rows="5" ng-model="newitem.description" placeholder="Description"></textarea>
    <br>
    <label>Photo:</label><input type="file"  accept="imag/works" ngf-select="" ngf-multiple="true"  class="form-control" id="img" name="img" placeholder="Image" ng-model="newitem.photo" multiple>
    <br>
    <button type="submit">Save</button>
</form>
<div ng-show="sendmessage">
    Item Saved Successfully...........
</div>

<div>

}

所有教程,Android开发人员指南和书籍都建议将Binder作为内部服务类。真的必须只是内心阶级吗?

1 个答案:

答案 0 :(得分:0)

它是一个内部类,因此您可以轻松返回外部Service实例。你也可以把它变成一个外部类:

public class LocalBinder extends Binder {

  private final LocalService mLocalService;

  public LocalBinder(final LocalService service) {
    mLocalService = service;
  }

  LocalService getService() {
    return mLocalService;
  }
}

使用内部类可以避免创建字段和构造函数的麻烦。