Code example for ContextWrapper

Methods: bindServicestartServicesetClass

  public static ServiceToken bindToService(Activity context, ServiceConnection callback) {
      Activity realActivity = context.getParent();
      if (realActivity == null) {
          realActivity = context;
      ContextWrapper cw = new ContextWrapper(realActivity);
      cw.startService(new Intent(cw, MediaPlaybackService.class));
      ServiceBinder sb = new ServiceBinder(callback);
      if (cw.bindService((new Intent()).setClass(cw, MediaPlaybackService.class), sb, 0)) {
          sConnectionMap.put(cw, sb);
          return new ServiceToken(cw);
      Log.e("Music", "Failed to bind to service");
      return null; 
  public static void unbindFromService(ServiceToken token) {
      if (token == null) {
          Log.e("MusicUtils", "Trying to unbind with null token");
Contextual code suggestions in your IDE  Get Codota for Java