A broadcast receiver is a class in your Android project that is responsible for receiving all intentions that are sent by other actions using android.content.ContextWreapper.sendBroadcast(Intent intent)
In the manifest file that you receive, you must declare which is your broadcast receiver, for example:
<receiver android:name="xyz.games.pacman.network.MessageListener"> <intent-filter> <action android:name="xyz.games.pacman.controller.BROADCAST" /> </intent-filter> </receiver>
As you can see, you also define an intent filter here, that is, what intentions should be accepted by the broadcast receiver.
Then you need to define a class that extends BroadcastReceiver. This is the class that you defined in the manifest file:
public class MessageListener extends BroadcastReceiver { @Override public void onReceive(Context context, Intent intent) { ... }
Here, all intentions that are passed through the filter are accepted, and you can access them using the parameter passed in the method call.
RoflcoptrException
source share