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 6693015
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T05:56:02+00:00 2026-05-26T05:56:02+00:00

My activity has registered a BroadcastReceiver using registerReceiver() . I would like to update

  • 0

My activity has registered a BroadcastReceiver using registerReceiver(). I would like to update some UI when a broadcast is received.
In my experiment I found the context happen to be my activity(singleinstance),

public void onReceive(Context context, Intent intent) {
        Log.d(tag, context.getClass().getName());
}

but I am not sure if it is always the case as the docs are not clear about it.
Can I just cast the context parameter to my activity?

What would be a good practice to change activity in BroadcastReceiver.onReceive?

  • 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-26T05:56:03+00:00Added an answer on May 26, 2026 at 5:56 am

    If you want Update UI, take one Receiver as inner class of activity and broadcast action. Now catch inside onReceive() and update activity.
    You should unregister it after use is over
    and context is always of the activity that register broadcast as a onReceive(). You can send a broadcast from service to initiate the update if you are doing calculation in service.

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

Sidebar

Related Questions

How would I calculate the total time an activity has been displayed on the
I have a mapView activity that has a LocationListener registered to check for a
I have an activity that has a TabHost containing a set of TabSpecs each
My task is to simulate activity of couple of persons. Each of them has
The main activity includes some variables with set values. I created a sub-activity with
For tracking user activity, I am using a Windows Hook for the main application
My project has an Activity Monitor that monitors the activity of a user. Currently
My activity has a set of buttons on the left half of the screen
I have a widget it has a button which starts another activity and that
My application starts from an Main activity and this main activity has its own

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.