android - One Service communicating with two Activity and another service -


So, this is my scenario: I have two activities and a service - & gt; All three (classes) require return type values ​​from second service (hence, total 2 activities, 2 in the application service).

i.e: activity A, start -> An activity B and a service I.

Activity B, Start - & gt; A Service II.

After this, activity A, B and Service II have to communicate with the service. The service I am always running behind and never stops at the start.

was as follows:

  1. Four. The three who declare the interface between the transmitted classes Write ADL files.

  2. Create an activity, then create Service I, Activity B and create Service B from Service II.

  3. As a service, I can do the only one () method for communication with 3 sections, at any given time, what I am doing is that from 3 classes All the objectives are different by telling different values ​​using different set sets () properties.

  4. When communication should be done by using InitService () and release release should be released immediately after using ().

  5. On Service I, the onBind () method is already being used for 3 sections, using the getType () property, and return the respect now IBCinder type.

    Now, my problem is at step 5. In which the onBind () method can not perform the checks for getType () of each intents and give the corresponding return type. Here is my code, service in the On-Binder () method. I:

      @Override Public IBinder onBind (intended for last intent) {Log D. (Main_Service.TAG, "it's connected"); If {intent.getType == "Activity_A"} {new activity_a_addel. Stub () {throws a remote1 (string 1, string p1, string p2) function {public from zero} {// something to do}}}} (intent.getType = "Activity_B") {new activity_b_aidl.Stub () Throws back {public int functions (2) RemoteException {/ something some_integer_values ​​return; }};} If (intent.getType () = "Service_II") {New service_II_aidl.Stub () {Public Boolean Function throws (3) (String U, String P) Remote Extension {// Some Return boolean_type_variable; Error: as the show in log seat: java.lang.NullPointerException  

    from all 3 orbits (Activity A, B and Service II) where ever I was calling a function within the attempt-grab block

    Can anyone tell me where I am wrong?

    - Kishore Devnath, (3rd year, CSE student).

    Without commenting on your entire design, I will add that the service to differentiate between the callers The way to use the 'action' property I do not know what is initService (), but when I am connected to a remote service, I just use bindService () so that's something in your activities: < / P>

      Bind service (new intent ("com.mypackage.myService.ACTION_1"), This, Context. BIITOSAORATAIT);   

    Or. ACTION_2 or. ACTION_3.

    Then your content is clearly an intent filter:

       & Lt; Action Android: name = "com.mypackage.myService.ACTION_2" /> & Lt; Action Android: name = "com.mypackage.myService.ACTION_3" /> & Lt; / Intent-Filter & gt;   

    Then use the intent in onBind () of the service. To identify the caller, getAction () to return the string. (Use the appropriate .equals () method to match the string!) And return the appropriate ibinders

    I do not think the extras on the intersection are passed through the service. I have not been forced to serve with any other service but I think it can work.

    As the last point, I only use AIDL and a remote service because for commercial reasons, I need functionality, different. Apks. There is no good technical reason to use it, in fact the opposite.

Comments

Popular posts from this blog

qt - switch/case statement in C++ with a QString type -

python - sqlite3.OperationalError: near "REFERENCES": syntax error - foreign key creating -

Python's equivalent for Ruby's define_method? -