tags:

views:

254

answers:

1

I have a snippet of code that I'm calling from a service:

        context.registerReceiver(new BroadcastReceiver(){ 

        @Override 
        public void onReceive(Context context, Intent intent) { 
            try {
                WifiManager mWm = (WifiManager) context.getSystemService(Context.WIFI_SERVICE);
                ret = mWm.isWifiEnabled();

              //DO MORE STUFF HERE
            } catch (Exception e) {
            }
        } 

    }, new IntentFilter(WifiManager.WIFI_STATE_CHANGED_ACTION)); 

What I would like is a way to check and make sure that the registerReceiver isnt already listening before it calls it again. Is this possible?

For example if my snippet of code is in a method, and I call the method 10 times, right now the onReceive method appears to run 10 times.

+3  A: 
Christopher
Looks like you are right, I needed to use a Thread in my service to keep it from firing off over and over.
pcm2a