title: Close application from broadcast receiver
body: <p>I'm new in android programming.
  I've tried registering broadcast receiver in activity, but my receiver not working when apps onPause.
  So i found that i need to registering my receiver in manifest.</p>
  
  <p>My objective is to close my application for some time after user turn off Wifi.</p>
  
  <p>This is my code but its not working.</p>
  
  <pre><code>public class ReceiverWifi extends BroadcastReceiver {
  
      @Override
      public void onReceive(Context context, Intent intent) {
  
          Handler handler = new Handler();
          Runnable runnable = new Runnable() {
  
              @Override
              public void run() {
                  MainActivity m = new MainActivity();
                  m.finish();
  
              }
          };
  
          if (intent.getAction().equals(WifiManager.WIFI_STATE_CHANGED_ACTION)) {
  
              int newWifiState = intent.getIntExtra(WifiManager.EXTRA_WIFI_STATE,
                      WifiManager.WIFI_STATE_UNKNOWN);
  
              switch (newWifiState) {
  
              case WifiManager.WIFI_STATE_DISABLED:
  
                  Toast.makeText(context, "Wi-fi Disconnected ",
                          Toast.LENGTH_SHORT).show();
  
                  handler.postDelayed(runnable, 15 * 1000);
                  break;
  
              }
          }
  
      }
  }
  </code></pre>
  
  <p>my manifest : </p>
  
  <pre><code>&lt;receiver android:name="com.example.wifimonitor.ReceiverWifi" &gt;
      &lt;intent-filter&gt;
          &lt;action android:name="android.net.wifi.WIFI_STATE_CHANGED" /&gt;
      &lt;/intent-filter&gt;
  &lt;/receiver&gt;
  </code></pre>
  
  <p>How do i achieve my objective?</p>