title: onReceive works only once android
body: <p>I am using this code to detect when the screen gets locked and call a toast, it works every time the screen gets locked. However, whenever i go out of the app, it stops working. it only works if the app is open.</p>
  
  <pre><code>public class BatterySaverLiteReceiver extends BroadcastReceiver {
  
      @Override
      public void onReceive(Context context, Intent intent) {
          if (intent.getAction().equals(Intent.ACTION_SCREEN_OFF)) {
              Log.i("Check", "Screen went OFF");
              Toast.makeText(context, "screen OFF", Toast.LENGTH_LONG).show();
  
              task(context);
          } else if (intent.getAction().equals(Intent.ACTION_SCREEN_ON)) {
              Log.i("Check", "Screen went ON");
              Toast.makeText(context, "screen ON", Toast.LENGTH_LONG).show();
          }
      }
  
      private void task(Context context) {
          // Process Killer and display all package names in toast
          ActivityManager actvityManager = (ActivityManager) context
                  .getApplicationContext().getSystemService(
                          context.getApplicationContext().ACTIVITY_SERVICE);
          List&lt;RunningAppProcessInfo&gt; procInfos = actvityManager
                  .getRunningAppProcesses();
          for (int pnum = 0; pnum &lt; procInfos.size(); pnum++) {
              actvityManager
                      .killBackgroundProcesses(procInfos.get(pnum).processName);
          }
      }
  }
  </code></pre>
  
  <p>thats how im registering my receiver</p>
  
  <pre><code>IntentFilter filter = new IntentFilter(Intent.ACTION_SCREEN_ON);
  filter.addAction(Intent.ACTION_SCREEN_OFF);
  mReceiver = new BatterySaverLiteReceiver();
  registerReceiver(mReceiver, filter);
  </code></pre>
  
  <p>manifest</p>
  
  <pre><code>   &lt;receiver android:name=".BatterySaverUltraReceiver" &gt;
          &lt;intent-filter&gt;
              &lt;action android:name="android.intent.action.SCREEN_OFF" /&gt;
              &lt;action android:name="android.intent.action.SCREEN_ON" /&gt;
          &lt;/intent-filter&gt;
      &lt;/receiver&gt;
  </code></pre>
  
  <p>i got this code from <a href="https://stackoverflow.com/questions/9477922/android-broadcast-receiver-for-screen-on-and-screen-off">here</a></p>