Note that there are some explanatory texts on larger screens.

plurals
  1. POOne Service communicating with two Activity and another service
    text
    copied!<p>So, Here is my scenario: I have two activity and one service --> all three(classes) requires a return type value from another service(so total 2 activity, 2 service in the application).</p> <p>i.e: Activity A, starts --> an Activity B and a Service I.</p> <p>Activity B, starts --> a Service II.</p> <p>Thereafter, Activity A, B and Service II has to communicate with Service I. Service I is always running behind and never stops once started.</p> <p>My approach of doing that was as follows:</p> <ol> <li><p>Write three .aidl files that declares the interface between the four communicating classes.</p></li> <li><p>Create Activity A, then create Service I, Activity B;and from Activity B create Service II.</p></li> <li><p>As Service I can have only one onBind() method, for communicating with the 3 classes at any time, what i'm doing is that all intent from 3 classes are differentiated by assigning different value using setType() property.</p></li> <li><p>Connection is built between each two classes when communication has to be done using initService() and released soon after that using releaseService().</p></li> <li><p>At Service I, the onBind() method has to first check from which of the 3 classes the intent is coming, using getType() property, and return the respective IBinder type.</p></li> </ol> <p>Now, my problem is at step 5. in which the onBind() method can't perform the operation of checking the getType() of every intents and give the respective return type. Here is my code, for onBinder() method in Service I:</p> <pre><code>@Override public IBinder onBind(final Intent intent){ Log.d(Main_Service.TAG,"it got connected"); if(intent.getType=="Activity_A") { return new Activity_A_aidl.Stub() { public void function1(int u1,String p1,String p2) throws RemoteException{ //do something } };} if(intent.getType=="Activity_B"){ return new Activity_B_aidl.Stub() { public int function2() throws RemoteException{//do something return some_integer_values; } };} if(intent.getType()="Service_II"){ return new Service_II_aidl.Stub(){ public boolean function3(String u,String p) throws RemoteException{ //do something return boolean_type_variable; } };} } </code></pre> <p>error: as show in LogCat: java.lang.NullPointerException</p> <p>from all 3 classes(Activity A,B &amp; Service II) where-ever i'm calling one of the functions within try-catch block. </p> <p>Can anyone tell me where am i going wrong.</p> <p>-Kishore Debnath, (3rd yr, CSE Student).</p>
 

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