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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T10:50:43+00:00 2026-06-04T10:50:43+00:00

A have a little confuse the difference between Widget Context and Application Context :

  • 0

A have a little confuse the difference between Widget Context and Application Context:
Regarding problem relate with unable to register new BroadcastReceiver via implement source code of Android Widget (Ref.1)


For readability reason, i copy my answer as below:
★Problem by Henry (Ref.1):

I am making a widget that needs a
broadcast receiver, like the one in
com.example.android.apis.appwidget.ExampleBroadcastReceiver.
However, the example defines
Intent.ACTION_TIMEZONE_CHANGED in the
manifest, but there are some that do
not allow this

For example, Intent.ACTION_TIME_TICK
says “You can not receive this through
components declared in manifests, only
by exlicitly registering for it with
Context.registerReceiver(). “

So I removed the manifest declarations
and tried replacing the
AppWidgetProvider.onEnabled function
that was in the example with a call
like the following:
context.registerReceiver(myReceiver,
new
IntentFilter(Intent.ACTION_TIME_TICK));

(where “myReceiver” is an instance of
the receiver I want.) However, when I
try to run the code, I get the
following error:

Unable to start
receiver…android.content.ReceiverCallNotAllowedException:
IntentReceiver components are not
allowed to register to receive intents

★Our analysis this issue and solution for this problem (Ref.1)

This is result after investigate this
problem, i was handler successful this
issue. So i collect as report to share
with android developer. Hope it help

Here is result:

❶ISSUE:*
Regarding limited from Widget, when try to register
BroadcastReceiver via explicit source
code: (No effect when register
BroadcastReceiver via Manifest.xml)

❷EXAMPLE: *
BroadcastReceiver: ACTION_TIME_TICK message is one
example: As docs from Android had
point out: “You can not receive this
through components declared in
manifests, only by exlicitly
registering for it with
Context.registerReceiver().” (Ref.1)

❸PREVIOUS SOLUTION:* Code Snippet: context.registerReceiver(this,
intentName); (1)

❹ERROR when used 3★ solution* When implement follow (1), it though
exception:
android.content.ReceiverCallNotAllowedException:
IntentReceiver components are not
allowed to register to receive intents

★Good news for anyone who need to
register BroadcastReceiver in Widget
🙂 we CAN register successful
BroadcastReceiver

❺OUR SOLUTION:* But, We can fixed this by used application context
instead of Widget context(*) Code
Snippet:
context.getApplicationContext.registerReceiver(this,
intentName);

❻REFERENCE:* http://developer.android.com/reference/android/content/Intent.html#AC…
Regarding

❼TARGET ENVIRONEMNT:* SDK 2.3, both on Emulator and NexusOne 2.3, If
anyone success with this solution
please update our report

❽NOTES* May be difference between Context object of widget and
application, but i still don’t known
exactly cause of this problem.

Please let me known if your have
better solution or explain more
clearly

Also i had solver this problem, but i
still don’t known exactly cause of
this problem.

Please let me known if your have
better solution or explain more
clearly


★CONCLUTION:

● NG: When use Widget context to register BroadcastReceiver

context.registerReceiver(this, intentName); 

-> it thought exception:

Unable to start receiver...android.content.ReceiverCallNotAllowedException: IntentReceiver components are not allowed to register to receive intents

● OK: When use Application context everything working fine:

ontext.getApplicationContext.registerReceiver(this, intentName); 

★QUESTION:
Also our solution can solver problem: “unable to register new broadcast message via implement source code of Android widget”.

But i still concern two Qestion:

Question❶: The difference between Widget Context and Application Context and other Context object (Activity Context)’

Question❷: Because context object was use usually so when to use Application context and when to use other Context.

For ❷ i had found explain relate with memory leak (Ref. 2), but i think it may not enough (Ref.2)

So if your have answer please let me known, any answer appreciated.

Thanks


★Referecens:

(1) http://groups.google.com/group/android-developers/browse_thread/thread/790da1a655f4a227/0b8d6aad1dc2d371?hl=en&lnk=gst&q=Broadcast+Receiver+From+Widget#0b8d6aad1dc2d371

(2) http://developer.android.com/resources/articles/avoiding-memory-leaks.html

  • 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-06-04T10:50:44+00:00Added an answer on June 4, 2026 at 10:50 am

    This question is over a year old and is definitely long and complicated and the English language is difficult to understand. However, it still probably deserves some kind of answer.

    If I understand, you are basically asking for the difference between the different Android Context objects. The main difference is scope or lifetime.

    The application’s Context (that you can get with Activity.getApplicationContext() or Context.getApplicationContext() has a lifetime of your entire application. The application Context is created when your application (or parts of it) are started. It lives (more or less) forever.

    An activity’s Context is created when that Activity is created and goes away when that activity is destroyed. If you are doing anything with the UI, you need to do that using the activity’s Context so that when the activity is destroyed, those things that are related to that activity are also cleaned up.

    There are other Contexts like the one you get in a BroadcastReceiver or an AppWidgetProvider in onReceive(). This Context has a very short lifetime (it is destroyed immediately after the onReceive() method returns). Therefore you can only do limited things with this Context.

    You want to register a Receiver to listen for the broadcast Intents you are interested in. You cannot do this with the Context you get in onReceive() because that Context has a short lifetime and the listener has to be linked to something. In this case you can use the application’s Context to link the listener to. This works, but you need to realize that you’ve created some objects that will never go away because they are always active. At least you should make sure that you clean this up when the user deletes your widget from his home screen by removing the listener using unregisterReceiver().

    There are a lot of questions/answers on StackOverflow regarding usage of Context. For example, What's the difference between the various methods to get a Context?

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

Sidebar

Related Questions

I have 2 questions: First, what's the difference between a web application and a
I'm a little confused. We have developed an net 4.0 application. We use nhibernate
I am little bit confused about following problem & their solutions: i have 2
I am little confused about the difference between containers and collections. I read about
I have a little problem picking the right language to write my daemon, I
I am a little confused with Hibernate. My problem is the following: I have
I'm a little confused by the difference between Java and Android Java. Let's say
I'm a Python newbie. I have been a little confused by the differences between
What is the difference between cmake and ccmake ? I have the Ubuntu package
I'm a little confused about the difference between the definitions of protocols on Linux

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.