Custom broadcast,
Custom Broadcast
Custom broadcasts are broadcast senders and broadcast receivers.
:
Analysis:
1. Write your own broadcast senders
Set the broadcast id, which must be monitored by the broadcast receiver.
Intent. setAction ("com. fry. Cycler ");
This is to bring data to the broadcast receiver.
Intent. putExtra ("key", "this is the data that the Broadcast Sender brings to the receiver ");
Send Broadcast
SendBroadcast (intent );
Set the broadcast permission. Only the broadcast receiver with this permission can receive messages from the Broadcast Sender,
Of course, this permission can also be left unspecified.
SendBroadcast (intent, "com. fry. permission. xxx ");
2. Set the broadcast receiver's permissions and listening objects
Permission:
Note the custom permission method here.
Listener object:
The first package for the receiver at registration, and the second package is the id of the Broadcast Sender.
3. Write broadcast Receiver