Joke Collection Website - Blessing messages - How does android send specific broadcasts?
How does android send specific broadcasts?
the method of sending broadcast (intention) by Android.
①:Intent myIntent = new Intent(); -create Intent object
②: myintent. setaction (string)-set the general action to be executed. Parameter: Action The name of an action, such as ACTION_VIEW. The specific actions of the application should be prefixed with the package name of the supplier.
③: myintention. putextra (String, object)-extra data sent in the broadcast, where string is a user-defined key and object represents multiple data types
④: send broadcast (myintention); -send a broadcast
receive a broadcast
the way Android receives a broadcast is to register a broadcast receiver (my receiver, intent filter).
①: firstly, create MyReceiver class (class name customization) to inherit the BroadcastReceiver class. -create a broadcast receiver
②: rewrite the public void on receive (context context, intent) method in MyReceiver. This method is triggered after a broadcast is received. -rewrite processing method
③: instantiate MyReceiver class in methods such as Activity or Service startup onCreate (), onStartCommand ()-instantiate broadcast receiver at startup
④: intentfilter = new intentfilter (); -create the IntentFilter object intention filter
⑤: filter. addaction (string); -add a filter condition to the filter to explain what broadcast to receive
⑥: register receiver (cmd receiver, filter); -Register the broadcast, with the parameter (broadcast receiver, intention filter).
- Previous article:Parents' birthday wishes
- Next article:Greeting messages to elders during the May Day holiday.
- Related articles
- Send a message to your best friend to congratulate her on her 30th birthday.
- The Teacher’s Day greetings include dual metaphors, personification of rhetoric, etc., please leave it to the experts! ! !
- Libra doesn't answer his phone or return his text messages. Why?
- Quick command library Apple ios shortcut key daquan
- Hello, how to untie the mobile broadband of the mobile phone for two years? I don't want to use it now
- Mobile phone fetion charging problem
- Inspirational words on the last day of the month to inspire the team on the last day of the first half of the year
- Is it a scam to receive Tuanyou link via text message?
- What's wrong with WeChat voice without sound?
- How to send text messages to Japanese mobile phones? Softbank