Esempio n. 1
0
  @Override
  public boolean bindService(Intent intent, ServiceConnection connection, int flags) {

    if (VaporServiceConnection.class.isAssignableFrom(connection.getClass())) {
      VaporServiceConnection vsc = ((VaporServiceConnection) connection);

      // We only attempt to bind if we aren't already bound to this
      // service
      if (!conns.containsKey(vsc.serviceClass())) {
        return super.bindService(intent, vsc, flags);
      } else {
        Log.w(
            shortName + ".bindService(Intent,ServiceConnection,int)",
            "Already bound to "
                + vsc.serviceClass()
                + ". To avoid service leaks you must unbind from the service first.");
      }
      return false;
    } else {
      Log.w(
          shortName + ".bindService(Intent,ServiceConnection,int)",
          "This service binding will NOT be managed by Vapor as 'connection' is not an instance of VaporServiceConnection. \nUse .vsc(Class<? extends Service>) to obtain a VaporServiceConnection for your Service");
      return super.bindService(intent, connection, flags);
    }
  }
Esempio n. 2
0
  @Override
  public void unbindService(ServiceConnection connection) {

    if (VaporServiceConnection.class.isAssignableFrom(connection.getClass())) {
      // attempt cast
      VaporServiceConnection vsc = ((VaporServiceConnection) connection);

      // delegate call to new method that can accept just the service
      // class
      unbindService(vsc.serviceClass());
    } else {
      Log.i(
          shortName + ".unbindService(ServiceConnection)", "Unbinding unmanaged ServiceConnection");
      super.unbindService(connection);
    }
  }