Hi all,

I would like to register a broadcast receiver on onStart of an
activity and then unregister the receiver when the activity gets
onStop called. When I debug I see that both of these calls are made
when I expected, but for some reason, my broadcast receiver keeps
handling intents.

Can someone please enlighten me as to why the receiver is still
processing intents, even when I have called unregistered the receiver?

Best regards,

Alex

public class Main extends Activity {
        private static final String SMS_RECEIVED
="android.provider.Telephony.SMS_RECEIVED";

        SMSReceiver r;
        IntentFilter smsFilter ;
        int resume = 0;
        int pause = 0;

        @Override
        public void onCreate(Bundle savedInstanceState) {
                super.onCreate(savedInstanceState);
                setContentView(R.layout.main);
                r = new SMSReceiver();
                smsFilter = new IntentFilter();
                smsFilter.addAction(SMS_RECEIVED);
        }

        @Override
        protected void onStart() {
                this.registerReceiver(r, smsFilter);
                resume++;
                super.onStart();
        }

        @Override
        protected void onStop() {
                this.unregisterReceiver(r);
                pause++;
                super.onStop();
        }
}



<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android";
      package="com.SMSHandsFree"
      android:versionCode="1"
      android:versionName="1.0">
    <application android:icon="@drawable/icon" android:label="@string/
app_name">
        <activity android:name=".Main"
                  android:label="@string/app_name">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category
android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>

    </application>
    <uses-sdk android:minSdkVersion="3" />
        <uses-permission android:name="android.permission.RECEIVE_SMS" />
        <uses-permission android:name="android.permission.READ_CONTACTS" />
</manifest>

-- 
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