How To Register Android BroadcastReceiver Statically

In previous article we have learnt how to dynamically register and unregister android broadcast receiver in java code. This example will show you how to  register android broadcast receiver statically in android manifest xml file.

1. Dynamic Register VS Static Register.

  1. Dynamic register and unregister broadcast receiver is very flexible.
  2. You can dynamically register all broadcast intent actions in java code.
  3. But when dynamically register, it can receive the broadcast message only after the android app startup, because the register broadcast receiver action is occurred in activity onCreate() method.
  4. Static broadcast receiver register can resolve above issue. When you register a broadcast receiver in static mode, the android OS will create a new process to handle the broadcast even the app do not startup.
  5. But static register can not handle all broadcast action events.

2. How To Create Static Register Android Broadcast Receiver.

  1. Right click the package name, click New —> Other —> Broadcast Receiver in popup menu.
    create a new static android broadcast receiver in android studio
  2. Input the broadcast receiver class name in the popup panel as below. Check Exported checkbox if you want the app to receive broadcast message from other app. Check Enabled checkbox to make the broadcast receiver enabled.
    android studio new broadcast receiver panel
  3. Click Finish button, then you can see the java class is created, it also extends android.content.BroadcastReceiver. Then input below code in the onReceive()

    package com.dev2qa.example.broadcast.receiver;
    import android.content.BroadcastReceiver;
    import android.content.Context;
    import android.content.Intent;
    import android.widget.Toast;
    public class BootCompleteReceiver extends BroadcastReceiver {
        // When receive BOOT_COMPLETE broadcast, show a toast popup. 
        public void onReceive(Context context, Intent intent) {
            Toast.makeText(context, "Android device boot complete.", Toast.LENGTH_LONG).show();
  4. After that you can see a receiver xml tag has been added in AndroidManifest.xml file as below.Because we want this broadcast receiver listen android device boot complete event, so we add an intent-filter with action android.intent.action.BOOT_COMPLETED.To listen above action event, this app need add android.permission.RECEIVE_BOOT_COMPLETED permission in AndroidManifest.xml file also.AndroidManifest.xml
    <manifest xmlns:android=""
       <!-- Need to add below permission to receive boot complete broadcast message.-->
        <uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED"/>
                <!--Configured this broadcast receiver to receive boot complete broadcast event.-->
                    <action android:name="android.intent.action.BOOT_COMPLETED" />
  5. Now when you start the android emulator, you can see a toast message popup as below picture.

If you can not watch the above video, you can see it on the youtube URL

0 0 votes
Article Rating
Notify of

This site uses Akismet to reduce spam. Learn how your comment data is processed.

1 Comment
Oldest Most Voted
Inline Feedbacks
View all comments

“When you register a broadcast receiver in static mode, the android OS will create a new process to handle the broadcast even the app do not startup.”

The Broadcast Receiver is registered during the first app start, so your above comment is in-correct for first app start scenario.

Would love your thoughts, please comment.x