title: Keep broadcast receiver running after application is closed
body: <p>I need to keep broadcast receiver running all the time after app has been started.</p>
  
  <p>Here is the code that registers this receiver in the application</p>
  
  <pre><code>    IntentFilter filter = new IntentFilter(Intent.ACTION_SCREEN_ON);
      filter.addAction(Intent.ACTION_SCREEN_OFF);
      BroadcastReceiver mReceiver = new ScreenEventsReceiver();
      registerReceiver(mReceiver, filter);
  </code></pre>
  
  <p>And code for receiver</p>
  
  <pre><code>public class ScreenEventsReceiver extends BroadcastReceiver {
       public static boolean wasScreenOn = true;
  
       @Override
       public void onReceive(Context context, Intent intent) {
          if (intent.getAction().equals(Intent.ACTION_SCREEN_OFF)) {
              wasScreenOn = false;
              Log.d("ScreenEventReceiver", "ON");
          } else if (intent.getAction().equals(Intent.ACTION_SCREEN_ON)) {
              wasScreenOn = true;
              Log.d("ScreenEventReceiver", "ON");
          }
       }
  }
  </code></pre>