相关疑难解决方法(0)

如何访问MediaBrowserServiceCompat服务的实例?

令人惊讶的是,我很难抓住源自的服务实例MediaBrowserServiceCompat.

对于典型的服务,为了实现这一点,使用本地绑定器

class MyService extends MediaBrowserServiceCompat {
  class MyBinder extends Binder {
    public MyService getService() {
      return MyService.this;
    }

  private final MyBinder binder = new MyBinder();

  @Override
  public IBinder onBind(Intent intent) {
    return binder;
  }

  public void doMagic() { // <-- How to call this from activity?
    // ...
  }
}

// At the activity, for example, this binder is retrieved through 
// `onServiceConnected()`, typecast to `MyBinder` and thus 
// `getService()` gets us the service instance.
Run Code Online (Sandbox Code Playgroud)

但是,这不适用于派生的服务MediaBrowserServiceCompat …

android android-service android-mediaplayer android-support-library android-service-binding

1
推荐指数
1
解决办法
1157
查看次数