Android BroadcastReceiver suggest change

Communicate two activities through custom Broadcast receiver

You can communicate two activities so that Activity A can be notified of an event happening in Activity B.

Activity A

final String eventName = "";

protected void onCreate(Bundle savedInstanceState) {

protected void onDestroy() {

private void registerEventReceiver() {
    IntentFilter eventFilter = new IntentFilter();
    registerReceiver(eventReceiver, eventFilter);

private BroadcastReceiver eventReceiver = new BroadcastReceiver() {
    public void onReceive(Context context, Intent intent) {
         //This code will be executed when the broadcast in activity B is launched

Activity B

final String eventName = "";

private void launchEvent() {
    Intent eventIntent = new Intent(eventName);

Of course you can add more information to the broadcast adding extras to the Intent that is passed between the activities. Not added to keep the example as simple as possible.

Feedback about page:

Optional: your email if you want me to get back to you:

Table Of Contents
64 Menu
112 Loader
119 Xposed
132 Colors
135 Fresco
140 AdMob
147 Button
156 Vk SDK
170 XMPP
176 OpenCV
200 FileIO
203 Moshi
217 Paint
231 AIDL
241 JCodec
243 Okio
255 Looper
  ↑ ↓ to navigate     ↵ to select     Esc to close