Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3849816
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T16:54:48+00:00 2026-05-19T16:54:48+00:00

I know the BroadcastReceiver can’t be used if defined as Activity’s inner class. But

  • 0

I know the BroadcastReceiver can’t be used if defined as Activity’s inner class. But I wonder why? Is it because the system would have to instantiate a large Activity object to just have instantiated a receiver instance?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-19T16:54:49+00:00Added an answer on May 19, 2026 at 4:54 pm

    … because the system would have to instantiate a large Activity object to just have instanitated a recevier instance?

    Yup, just like any other non-static inner class. It has to get an instance of the outer class from somewhere (e.g. by instantiating or by some other mechanism) before it can create an instances of the (non-static) inner class.

    Global broadcast receivers that are invoked from intents in the manifest file that would be be instantiated automatically by the system have no such outer instance to use to create an instance of the broadcast receiver non-static inner class. This is independent of what the outer class is, Activity or not.

    However, if you are using a receiver as part of working with an activity, you can manually instantiate a broadcast receiver yourself in the activity (while one of the activity callbacks, you have an instance of the outer class to work with: this) and then register/unregister it as appropriate:

    public class MyActivity extends Activity {
    
        private BroadcastReceiver myBroadcastReceiver =
            new BroadcastReceiver() {
                @Override
                public void onReceive(...) {
                    ...
                }
           });
    
        ...
    
        public void onResume() {
            super.onResume();
            ....
            registerReceiver(myBroadcastReceiver, intentFilter);
        }
    
        public void onPause() {
            super.onPause();
            ...
            unregisterReceiver(myBroadcastReceiver);
        }
        ...
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a BroadcastReceiver catching ACTION_NEW_OUTGOING_CALL events. In the onReceive() method I'm sending the
I need my activity to handle HOME button press with a receiver programmatically, but
Does anybody know the working of android.intent.action.SYNC ? How would one go about testing
I know that we can bind the data to each control within ItemTemplate as
I know I can select the lines and use something like :w ! sort
I know how to take control of the back button. I have a VideoView
I have a program that monitors incoming SMS's, and I want it to monitor
i have the following pgm which responds with a Toast with an incoming msg
I currently have a Service in Android that is a sample VOIP client so
I have a particular situation: a service started by a broadcast receiver starts an

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.