Logo Icon Logo
A Crowd-sourced Cookbook on Writing Great Android® Apps
GitHub logo Twitter logo OReilly Book Cover Art
Intercommunication amongst ApplicationsBack to Android Cookbook Home | Up to Chapter: Inter/Intra-Application Communication

Author: Rachee Singh ('racheesingh')
In Published Edition? No
FormatLanguage: WikiFormat

Intercommunication amongst Applications


You need to get different applications deployed on a device to communicate. For instance, the running application wishes to notify another application (which is in the background) of a certain event.


To initiate communication, an application broadcasts an intent. The applications in the background that register a receiver for that particular intent will receive it and perform the necessary action in their BroadcastReceiver subclass.


To broadcast an intent from your application, insert the following code:

       Intent intent = new Intent("com.bluetooth.LINK_BROKEN"); 
       Log.d("My Class", "Intent Sent");

The application which wishes to be notified of an action from your application, needs the following code:

public class BluelinkIntents extends BroadcastReceiver {

	public void onReceive(Context context, Intent intent) {
	         Toast.makeText(context, "Application X Received the Intent!", oast.LENGTH_SHORT).show();
		Log.d("Application X", "Received the Intent!");


This code outlines a separate class which extends BroadcastReceiver. In this class, the application being notified can perform tasks once the intent is recieved.

These few lines of code have to be added to the AndroidManifest of the application which is being notified.

<!-- Receiver for Intent -->
        <receiver android:name="org.openintents.intents.BluelinkIntents" android:enabled="true" >
                <action android:name="com.bluetooth.LINK_BROKEN" />
                <category android:name="android.intent.category.DEFAULT" />

With all this set up, when your application starts, it will broadcast an intent. All the other applications present in the background on that Android device and which have the BroadcastReceiver set up will receive the intent and display a toast 'Application X Received the Intent!'.

See Also