title: unfortunately app is getting stopped while checking for network
body: <p>I am using the following code to check for the <strong>internet connection</strong> through out my app.</p>
  
  <pre><code>public class ConnectionChangeReceiver extends BroadcastReceiver
  {
    @Override
    public void onReceive( Context context, Intent intent )
    {
      ConnectivityManager connectivityManager = (ConnectivityManager)context.getSystemService( Context.CONNECTIVITY_SERVICE );
      NetworkInfo activeNetInfo = connectivityManager.getActiveNetworkInfo();
      NetworkInfo mobNetInfo = connectivityManager.getNetworkInfo(ConnectivityManager.TYPE_MOBILE );
  
      if (activeNetInfo != null)
      {
          Toast.makeText( context, "Active Network Type : " + 
                         activeNetInfo.getTypeName(), Toast.LENGTH_SHORT ).show();
      }
      if(mobNetInfo != null)
      {
          Toast.makeText( context, "Mobile Network Type : " + 
                            mobNetInfo.getTypeName(), Toast.LENGTH_SHORT ).show();
      }
    }
  }
  </code></pre>
  
  <p>And I have defined required permission in the manifest file.</p>
  
  <p>Whenever I try to <strong>disconnect / connect</strong> the network using F8 key I will receive <strong><em>"UNFORTUNATELY APP HAS STOPPED"</em></strong>, and I am not getting any print in <code>logcat</code>.</p>
  
  <p>Can I know what is the mistake I am doing?</p>