title: AIDL interface between two applications
body: <p>I've stuck a total wall with the AIDL interfacing. I've an app which has to be controlled via 3rd party application (I've enough control over this so I can ask them to implement what ever I need into their activity) </p>
  
  <p>Originally my app was also an activity with interface and everything but I've changed it to be a background service and for testing, I created a dummy app which manages to start the service app to the background.</p>
  
  <p>Now I would like a way to request method calls from the service (mainly; start, stop, sendData). I've created the .aidl files for both apps. The aidl file implements only one method (this is courtesy of some other question here.)</p>
  
  <pre><code>package foo.testapp;
  interface IScript 
  {
       String executeScript(String script); 
  }
  </code></pre>
  
  <p>while the other aidl is same except the package is "foo.otherapp". The implementations I've found online had same package for both aidl files, but for me this causes an error (guess this is just a problem on my part since I hate namespaces and packages so I often just name them badly, if it's important to change them, I can do it)</p>
  
  <p>The plan was to use this method to send a string to the service and just have a switch over predefined strings to call a correct method ( could also just implement three different methods if it improves the usage).</p>
  
  <p>Anyway... I can't get the aidl to connect, I get error "Unable to start service intent </p>
  
  <blockquote>
    <p>{act=foo.testapp.IScript } : not found</p>
  </blockquote>
  
  <p>I would this guess has something to do with my misunderstandings ie. packagenames or so)</p>
  
  <p>this is the implementation in my test <strong>activity</strong> app </p>
  
  <pre><code>private final IScript.Stub mBinder = new IScript.Stub()
  {
      @Override
      public String executeScript(String script) throws RemoteException
      {
          // TODO Auto-generated method stub
      }
  };
  IScript mService = null;
  private ServiceConnection mConnection = new ServiceConnection() 
  {
       public void onServiceConnected(ComponentName className, IBinder service) 
       {
           mService = IScript.Stub.asInterface(service);
       }
       public void onServiceDisconnected(ComponentName className) 
       {
           mService = null;
       }
   };
  </code></pre>
  
  <p>Then in OnCreate() method I'll do this:</p>
  
  <pre><code>bindService(new Intent(IScript.class.getName()),
              mConnection, Context.BIND_AUTO_CREATE);
  </code></pre>
  
  <p>In service class I have this;</p>
  
  <pre><code>@Override
  public IBinder onBind(Intent intent) 
  {
      // Select the interface to return.  If your service only implements
      // a single interface, you can just return it here without checking
      // the Intent.
      if (IScript.class.getName().equals(intent.getAction())) 
      {
          return mBinder;
      }
      return null;
  }
  
  /**
   * The IRemoteInterface is defined through IDL
   */
  private final IScript.Stub mBinder = new IScript.Stub() 
  {
      @Override
      public String executeScript(String script) throws RemoteException 
      {
          if (script == "test")
          {
              return "foo";
          }
          return "fail";
      }
  };
  </code></pre>
  
  <p>And finally the manifest files;</p>
  
  <p>well actually, I've no idea if I have to add something into manifest files when dealing with the aidl. In the one example I saw this;</p>
  
  <pre><code>    &lt;intent-filter&gt;
          &lt;action android:name="foo.otherapp.IScript" /&gt;
      &lt;/intent-filter&gt;
  </code></pre>
  
  <p>and</p>
  
  <pre><code>    &lt;intent-filter&gt;
          &lt;action android:name="foo.testapp.IScript" /&gt;
      &lt;/intent-filter&gt;
  </code></pre>
  
  <p>I would guess that the errors could be anywhere. I've been trying to set this up with chewing gum and band-aids. Guess I've just misunderstood some basic concept of this.</p>
  
  <p>Anyway, any help is welcome.</p>
  
  <p>Thanks in advance!</p>