Runtime exception after BroadcastReceiver
<p>I am trying to use BroadcastReceiver to get internet connection state.</p>

<p>The receiver class is like this:</p>

<pre><code>public class ConnectivityReceiver extends BroadcastReceiver {

    WebView mWebView;



    @Override
    public void onReceive(Context context, Intent intent) {
        String action = intent.getAction();
        Log.d(MSResearch.LOG_TAG, "Connectivity action: " + intent.getAction());
        if (action.equals(WifiManager.WIFI_STATE_CHANGED_ACTION)) {
            WifiManager wm = (WifiManager) context.getSystemService(Context.WIFI_SERVICE);
            Log.e(MSResearch.LOG_TAG, "Setting wifistate: " + wm.getWifiState());
        } else if (action.equals(ConnectivityManager.CONNECTIVITY_ACTION)) {
            NetworkInfo ni = intent.getParcelableExtra  (ConnectivityManager.EXTRA_NETWORK_INFO);
            Log.e(MSResearch.LOG_TAG, "Setting isConnected: " + ni.isConnected());
        }
    }
}
</code></pre>

<p>I instantiated the Receive in onCreate() function and tried to register the receiver in onResume() of my Activity class and unregister it in onPause().</p>

<pre><code>public onCreate(){
...
conReceiver = new ConnectivityReceiver();
itFilter = new IntentFilter(ConnectivityManager.CONNECTIVITY_ACTION);
itFilter.addAction(WifiManager.WIFI_STATE_CHANGED_ACTION);
...
}

@Override
public void onResume(){
    registerReceiver(conReceiver,itFilter);
}

@Override
public void onPause(){
   unregisterReceiver(conReceiver);
}
</code></pre>

<p>I am getting run time exception right after onResume call. Can anyone tell me what I did wrong? I even tried to simply add the receiver tag in the manifest xml file instead of registering inside my activity, however I still get runtime exception. I've tried this on both 2.2 and 2.3 emulator and got the same problem.</p>

<pre><code>Thread [&lt;1&gt; main] (Suspended (exception RuntimeException))  
    ActivityThread.performResumeActivity(IBinder, boolean) line: 3128   
    ActivityThread.handleResumeActivity(IBinder, boolean, boolean) line: 3143   
    ActivityThread.handleLaunchActivity(ActivityThread$ActivityRecord, Intent) line: 2684   
    ActivityThread.access$2300(ActivityThread, ActivityThread$ActivityRecord, Intent) line: 125 
    ActivityThread$H.handleMessage(Message) line: 2033  
    ActivityThread$H(Handler).dispatchMessage(Message) line: 99 
    Looper.loop() line: 123 
    ActivityThread.main(String[]) line: 4627    
    Method.invokeNative(Object, Object[], Class, Class[], Class, int, boolean) line: not available [native method]  
    Method.invoke(Object, Object...) line: 521  
    ZygoteInit$MethodAndArgsCaller.run() line: 868  
    ZygoteInit.main(String[]) line: 626 
    NativeStart.main(String[]) line: not available [native method]  
</code></pre>
