When you publish a component in the manifest, you don't instantiate that
component, the system will do so when it needs to.  In the case of broadcast
receiver, the system creates a new instance every time it needs to deliver
an intent to it.

On Mon, Aug 17, 2009 at 10:28 AM, R Ravichandran <[email protected]>wrote:

> Hello,
>
> I have an application that uses an extended BroadcastReceiver class inside
> the Activity. I have the extended BroadcastReceiver class as a member
> variable of the Activity class. But it looks like the receiver references
> keep changing between its construction and 'onReceive' method call. I would
> like to understand this better. Here are some details.
>
> public class MyEventReceiver extends BroadcastReceiver {
>
>     public MyEventReceiver(BNDialogInterface dlg) {
>         System.out.println("Receiver Object in constructor: "+this);
>     }
>
>     public void onReceive(Context context, Intent intent) {
>         System.out.println("Receiver Object in onReceive: "+this);
>     }
>
> }
>
> My Activity class:
>
> public class Notepadv2 extends Activity {
>     private MyEventReceiver receiver;
>
>     protected void onStart() {
>         // TODO Auto-generated method stub
>         super.onStart();
>         receiver = new MyEventReceiver(this);
>
>         Intent myIntent = new Intent("Test");
>          sendBroadcast(myIntent);
>     }
>
>
> }
>
> <?xml version="1.0" encoding="utf-8"?>
> <manifest xmlns:android="http://schemas.android.com/apk/res/android";
>     package="com.android.demo.notepad2">
>     <application android:icon="@drawable/icon">
>
>       <receiver android:name=".MyEventReceiver" android:enabled="true"
> android:exported="true">
>             <intent-filter>
>                <action android:name="Test" />
>             </intent-filter>
>     </receiver>
>
>         <activity android:name=".Notepadv2"
> android:label="@string/app_name">
>             <intent-filter>
>                 <action android:name="android.intent.action.MAIN" />
>                 <category android:name="android.intent.category.LAUNCHER"
> />
>             </intent-filter>
>         </activity>
>
> <activity android:name=".NoteEdit"></activity>
> </application>
> </manifest>
>
> >
>


-- 
Dianne Hackborn
Android framework engineer
[email protected]

Note: please don't send private questions to me, as I don't have time to
provide private support, and so won't reply to such e-mails.  All such
questions should be posted on public forums, where I and others can see and
answer them.

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

Reply via email to