Joke Collection Website - Blessing messages - Briefly describe how to send broadcast messages in android

Briefly describe how to send broadcast messages in android

1. Send broadcast

Intent intent = new Intent(BroadcastAction);

Bundle bundle = new Bundle();

bundle .putString("***", SUCCESS);

bundle.putString("FullPathName", mFullPathName);

intent.putExtras(bundle);

sendBroadcast(intent);

2. Create an internal class MyBroadcastReceiver in Activity to extend BroadcastReceiver and implement the onReceive method in it.

3. Declare a member variable of type MyBroadcastReceiver in Activity and register:

private MyBroadcastReceiver myBroadcastReceiver;

...

myBroadcastReceiver = new MyBroadcastReceiver();

IntentFilter filter = new IntentFilter();

filter.addAction(BroadcastAction);

registerReceiver(receiver, filter) ;

4. Remember to release after use

unregisterReceiver(receiver);

Note: The BroadcastAction in 1 and 2 must be the same Action