title: How to call method in activity from service in seperate process?
body: <p>I know how to call methods in service through aidl interface from activity. But how to call method in activity from service which is running in seperate process, without broadcast receiver ? </p>
  
  <p>Is there any way i can call methods in my activity through same aidl interface or other java interface ?</p>
  
  <p>Code:</p>
  
  <pre><code>//aidl interface
  interface IRemoteServiceCallback {
  
      void valueChanged();
  }
  
  //starting service in activity
  Intent serviceIntent = new Intent(BackgroundService.class.getName());
  serviceIntent.setPackage("com.example.service2");
  startService(serviceIntent);
  bindService(serviceIntent, mConnection, Context.BIND_AUTO_CREATE);
  
  
  //aidl stub implementation in activity
  private IRemoteServiceCallback mCallback = new IRemoteServiceCallback.Stub() {
  
      @Override
      public void valueChanged() {
  
          System.out.println("Callback method called");
      }
  };
  
  //service connection in activity
  BackgroundService mService = null;
  private ServiceConnection mConnection = new ServiceConnection() {
  
      public void onServiceConnected(ComponentName className, IBinder service) {
  
          System.out.println("Callback service connected");
          try {
  
              mService.registerCallback(mCallback);
          } catch (Exception e) {
  
              Log.e("Service2-CallbackService-Connecting:", e.toString());
          }
      }
  
      public void onServiceDisconnected(ComponentName className) {
  
          if (mService != null) {
              try {
                  mService.unregisterCallback(mCallback);
              } catch (Exception e) {
                  Log.e("Service2-CallbackService:", e.toString());
              }
          }
      }
  };
  
  // registering callbacks in service
  public void registerCallback(IRemoteServiceCallback mCallback) {
  
      System.out.println("Callback registers...");
      this.mCallback = mCallback;
  }
  
  public void unregisterCallback(IRemoteServiceCallback mCallback2) {
  
      this.mCallback = null;
  }
  
  //calling method
  mCallback.valueChanged();
  </code></pre>