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

  • SEARCH
  • Home
  • 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 880687
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T12:08:22+00:00 2026-05-15T12:08:22+00:00

I have an activity, it needs to response to a broadcast event. Since an

  • 0

I have an activity, it needs to response to a broadcast event.
Since an activity can not be a broadcast receiver at the same time,
I made a broadcast receiver.

My question is: how can I notify the activity from the broadcast receiver?
I believe this is a common situation, so is there a design pattern for this?

  • 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-15T12:08:22+00:00Added an answer on May 15, 2026 at 12:08 pm

    The broadcast is the notification. 🙂 If you want to say, start an activity or a service, etc., based on a received broadcast then you need a standalone broadcast receiver and you put that in your manifest file. However, if you want your activity itself to respond to broadcasts then you create an instance of a broadcast receiver in your activity and register it there.

    The pattern I use is:

    public class MyActivity extends Activity {
        private BroadcastReceiver receiver = new BroadcastReceiver() {
            @Override
            public void onReceive(...) {
                ...
            }
       });
    
        public void onResume() {
            super.onResume();
    
            IntentFilter filter = new IntentFilter();
            filter.addAction(BROADCAST_ACTION);
    
            this.registerReceiver(this.receiver, filter);
        }
    
        public void onPause() {
            super.onPause();
    
            this.unregisterReceiver(this.receiver);
        }
    }
    

    So, this way the receiver is instantiated when the class is created (could also do in onCreate). Then in the onResume/onPause I handle registering and unregistering the receiver. Then in the reciever’s onReceive method I do whatever is necessary to make the activity react the way I want to when it receives the broadcast.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an activity which needs to make two remote server calls. The first
I have a non-Activity class (let's call it NonActivity) that needs to post a
I have an Android Activity that needs to catch two different broadcasts. My current
I have an android activity that needs to call another activity (to get a
So I have an Activity (say TestActivity ) which needs to act as a
I have an activity (act2), which can be launched from act1 or act3. If
I have an activity indicator that is working fine. Most of the time. But
I have an activity, which when starting (onCreate or onStart) needs to manipulate some
Hi i have Tab activity(Chapter,subject) and database. i need to show the chapter_table content
I have an ArrayList of objects in one activity and I need this arrayList

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.