Note that there are some explanatory texts on larger screens.

plurals
  1. PObindService from other app but same userid/process
    primarykey
    data
    text
    <p>This is about memory-based IPC (like to <a href="http://developer.android.com/guide/topics/fundamentals/bound-services.html#Binder" rel="nofollow">LocalService</a> example) but for two apps running in the same process:</p> <p>I have two apps (<code>App1</code>, <code>App2</code>) and a shared project (<code>Shared</code>) which defines some interfaces and abstract classes for both apps:</p> <pre><code>Shared (regular Java project, references android.jar) - abstract myAbstractService - Binder myBinder App1 (Android Project, references Shared) - MainActivity App2 (Android Project, references Shared) - myService extends myAbstractService </code></pre> <p>Both apps run within the same process (<code>my.process</code>, defined in <code>&lt;application&gt;</code>), <code>App2</code> publishes <code>com.www.app2.myService</code>:</p> <pre><code>&lt;-- Both Apps run in the same process --&gt; &lt;manifest &lt;!-- *snip* --&gt; android:sharedUserId="my.shareduser"&gt; &lt;!-- ... --&gt; &lt;application &lt;!-- *snip* --&gt; android:process="my.process"&gt; &lt;-- App2 exports the service --&gt; &lt;service android:name="com.www.app2.myService" android:exported="true"&gt; &lt;intent-filter&gt; &lt;action android:name="com.www.app2.myService" /&gt; &lt;/intent-filter&gt; &lt;/service&gt; </code></pre> <p>This is the abstract <code>myAbstractService</code> (<code>myService</code> doesn't add anything new yet):</p> <pre><code>abstract public class GameClient extends Service { private static final String LOGTAG = "GameClient"; private myBinder binder = new myBinder(); public IBinder onBind(Intent intent) { Log.d(LOGTAG, "onBind()"); return this.binder; } public class myBinder extends Binder { public void sendMessage() { Log.d(LOGTAG, "sendMessage()"); } } } </code></pre> <p>When I try to bind to <code>myService</code> (App2) from my <code>MainActivity</code> (App1):</p> <pre><code>public void onServiceConnected(ComponentName name, IBinder service) { Log.d("MS", service.getClass().toString()); main.this.t = (myBinder) service; // Exception in this line of course } </code></pre> <p>I get an exception:</p> <blockquote> <p>DEBUG/MS(5464): class com.www.shared.myBinder<br> ERROR/AndroidRuntime(5464): java.lang.ClassCastException: com.www.shared.myBinder</p> </blockquote> <p>As both apps run in the same process, memory-coupled communication should work (at least I thought). I really don't want to use the message-based or broadcast-based communication as I'll send quite some messages around.<br> I suspect this exception happens due two different classloaders being used for the same class? Is this approach simply not possible/wrong or am I missing something?</p> <p><strong>Update:</strong><br> My aim is to write a very modular application, where App1 is used as a delegating and starting application of other modules (apps). As I don't want to ship <code>App1</code> with every app depending on it, I made it it's own app. </p> <p>Let's say I have a third app (App3, Android project). App2 &amp; App3 are both started by App1 (responsible for setting up connections while App2 &amp; App3 provide different application logic (but having the same interface). </p> <p>On a second thought I think this could be solved with an android library as well (App1 &amp; Shared merged as the library with <code>App2</code> and <code>App3</code> starting an Activity of this library and waiting for the result)? However the data is not parcelable (network connections) and I have no idea how this library could be distributed independently over the android market (like <code>App2</code> and <code>App3</code> are published there but ask for the library to be installed too). Would this resolve that problem at all?</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload