In activity, register a demo of the broadcast.
A total of 3 steps
First step: Define a Broadcastreceiver broadcast receive class:
Private New Broadcastreceiver () { @Override publicvoid onreceive (context context, Intent Intent) { = intent.getaction (); if (Action.equals (action_name)) { toast.maketext (Test.this, "handling the broadcast corresponding to the action name", ; } } };
Step Two: Register the broadcast:
Public void Registerboradcastreceiver () { new intentfilter (); Myintentfilter.addaction (action_name); // Register a broadcast registerreceiver (Mbroadcastreceiver, myintentfilter); }
Step three: Trigger the response
mbtnmsgevent = new button (this Span style= "color: #000000;" >); Mbtnmsgevent.settext ( send broadcast ); Mbtnmsgevent.setonclicklistener ( new Onclicklistener () {@Override public void OnClick (View v) {Intent mintent = new Intent (action_name); Mintent.putextra ( "Yaner", "send broadcast, equivalent to transmit data here" // send broadcast
Android Development Note "Broadcast components use"