Joke Collection Website - Blessing messages - How does android send specific broadcasts?

How does android send specific broadcasts?

Start a thread, sleep for one minute after each broadcast, and so on. (Or accept the system's timechanged broadcast, which seems to be sent once a minute).

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).