Hi,
I had tried initially by dynamically using registering the receivers
using the registerReceiver(). I get the callback when I the
application is in the foreground. The problem I faced was that, when I
exit the application, I never got a callback on the receiver when I
try to trigger it from my service class.
>From my service, I call:

Intent intent=new Intent(Consts.INTENT_UPDATE);
this.sendBroadcast(intent);

My receiver in my Activity class looks like this:

private BroadcastReceiver updateReceiver=new BroadcastReceiver() {

                @Override
                public void onReceive(Context context, Intent intent) {
                        // TODO Auto-generated method stub
                        if(Consts.INTENT_UPDATE.equals(intent.getAction()))
                        {
                                update();
                        }
                }
        };

I do not unregister my receivers at onDestroy() and register during
onCreate().
Is there something I am missing.

Thanks,
Priyank


On Nov 8, 3:13 pm, Mark Murphy <mmur...@commonsware.com> wrote:
> On Tue, Nov 8, 2011 at 2:45 PM, Priyank <priyankvma...@gmail.com> wrote:
> > Thanks for the reply. The 2 changes you mentioned made it work.
> > But the problem now I am facing is that, I cannot call a method which
> > belongs to the main class(BroadcastActivity ) from onReceive() since
> > the Receiver1 class is static. Is there any way to deal with this.
>
> Not the way you're going about the problem.
>
> > The reason I can not put the Receiver1 class in a different java file
> > is that there are many UI changes I do when I receive the broadcast.
>
> You will not be doing any changes to the UI when you receive the
> broadcast. If you wanted to do that, you would not be using a
> manifest-registered receiver. Use registerReceiver() in the activity
> to register a BroadcastReceiver dynamically; that receiver can then
> work with the activity to update the UI.
>
> For example, here is an application that uses ACTION_BATTERY_CHANGED this way:
>
> https://github.com/commonsguy/cw-advandroid/tree/master/SystemEvents/...
>
> --
> Mark Murphy (a Commons 
> Guy)http://commonsware.com|http://github.com/commonsguyhttp://commonsware.com/blog|http://twitter.com/commonsguy
>
> Android Training in NYC:http://marakana.com/training/android/

-- 
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

Reply via email to