Reputation:
My application has currently 2 services and 1 activity. My first service, called sensor, just return all the values of the sensors of the phone. Then I have a second service called Waypoint which is bound to send commands to my Arduino card for my robot to reach a waypoint. So, in a way, Sensor send the values to Waypoint. Moreover, I bound Waypoint to my Activity to "see" the commands which are sent. However, I don't know how to make my 2 services communicate (how can I send the values of the sensors to my Waypoint service ? ), would anyone have a tutorial about that ? I only saw tutorial about communication between services and activities...
Thank you all !
PS : Sorry for my english...
EDIT :
Thank you for your answers !
I just did what you both said but it seems not to work (i've no error, but nothing get displayed, i'd like to give you my code, but it's too long...). Well, if you have courage : http://paste.tgl0be.org/?id=10458.
Here is what i'm trying to do :
But nothing get displayed... Would anyone have an idea about the problem ? (someone who read my code, obviously)
I don't know if I respected the forum rules, indeed I don't think I ANSWERED my question... If so, sorry...
Again sorry for my english
New edit :
I can finally get some results, always 0 in fact... I wondered if my receiver is well declared into my AndroidManifest, as my receiver is an inner class of Waypoint, here is my code:
<?xml version="1.0" encoding="utf-8"?>
<application android:icon="@drawable/icon" android:label="@string/app_name">
<activity android:name=".Connexion"
android:label="@string/app_name">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<receiver class=".Waypoint$Receiver" android:name=".Waypoint$Receiver">
<intent-filter>
<action android:name="android.intent.action.EVENT_ACTION" />
</intent-filter>
</receiver>
<service android:name=".Sensors" android:enabled="true"/>
<service android:name=".Waypoint" android:enabled="true"/>
</application>
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_GPS" />
<uses-permission android:name="android.permission.ACCESS_ASSISTED_GPS" />
<uses-permission android:name="android.permission.LOCATION" />
I think it's not and it could explain the problem. The "$" symbol is used for an inner static class, and my Receiver is not static. Does anyone know how to declare a non-static inner class in the AndroidManifest ?
Upvotes: 2
Views: 4698
Reputation: 80330
Since your Sensor service communicates asynchronously with Waypoint service, you could have Sensor service send broadcast with extra data (sensor data) and Waypoint service would register BroadcastReceiver to get those broadcasts.
Upvotes: 2
Reputation: 64700
You can use the same communication techniques for Activity <-> Service between 2 services. I'd suggest http://developer.android.com/reference/android/app/Service.html#LocalServiceSample as one approach: the Sensor service will bind to the Waypoint service and can then send the values to it.
Upvotes: 0