title: Dynamic register to broadcast receiver not working
body: <p>When I'm setting my broadcast receiver as anonymous class his never called 
  but when I'm setting it as class and declare it on android manifest its work fine </p>
  
  <p>i want the ability of register and unregister the broadcast receiver dynamically
  why its won't working</p>
  
  <p>here is my code:</p>
  
  <pre><code>public class AppChangedProbe extends Probe.Base implements Probe.ContinuousProbe{
  
  private BroadcastReceiver appReceiver;
  
  
  @Override
  protected void onEnable() {
  
      IntentFilter filter = new IntentFilter();
  
  
      filter.addAction(Intent.ACTION_PACKAGE_ADDED);
      filter.addAction(Intent.ACTION_PACKAGE_REMOVED);
      filter.addAction(Intent.ACTION_PACKAGE_CHANGED);
  
  
      appReceiver = new BroadcastReceiver() {
          @Override
          public void onReceive(Context context, Intent intent) {
  
              if (intent.getAction().equals(Intent.ACTION_PACKAGE_REMOVED))
                  Logger.i(getClass(), "App Removed");
  
              if (intent.getAction().equals(Intent.ACTION_PACKAGE_CHANGED))
                  Logger.i(getClass(),"App Updated");
  
              if (intent.getAction().equals(Intent.ACTION_PACKAGE_ADDED))
                  Logger.i(getClass(),"App Added");
          }
      };
  
      getContext().registerReceiver(appReceiver, filter);
  }
  
  @Override
  protected void onDisable() {
      getContext().unregisterReceiver(appReceiver);
  }
  
  @Override
  protected boolean isWakeLockedWhileRunning() {
      return false;
  }
  </code></pre>
  
  <p>}</p>
  
  <p>the Probe.Base and Probe.ContinuousProbe are FUNF project jars.</p>
  
  <p>i set this permissions on the manifest:</p>
  
  <pre><code>&lt;uses-permission android:name="android.permission.BROADCAST_PACKAGE_REMOVED" /&gt;
  &lt;uses-permission android:name="android.permission.BROADCAST_PACKAGE_CHANGED" /&gt;
  &lt;uses-permission android:name="android.permission.BROADCAST_PACKAGE_ADDED" /&gt;
  </code></pre>
  
  <p>when i use the broadcast receiver as class its work</p>
  
  <p>here is the code that work:</p>
  
  <pre><code>public class AppChangedReceiver extends BroadcastReceiver {
  
  @Override
     public void onReceive(Context context, Intent intent) {
  
  
      if (intent.getAction().equals(Intent.ACTION_PACKAGE_REMOVED))
          Logger.i(getClass(),"App Removed");
  
      if (intent.getAction().equals(Intent.ACTION_PACKAGE_CHANGED))
          Logger.i(getClass(),"App Updated");
  
      if (intent.getAction().equals(Intent.ACTION_PACKAGE_ADDED))
          Logger.i(getClass(),"App Added");
  
  }
  </code></pre>
  
  <p>}</p>
  
  <p>and in the manifest:</p>
  
  <pre><code>&lt;receiver android:name =".sensors.EventBaseProbes.AppChangedReceiver"&gt;
          &lt;intent-filter android:priority="100"&gt;
              &lt;action android:name="android.intent.action.PACKAGE_REMOVED"/&gt;
              &lt;action android:name="android.intent.action.PACKAGE_CHANGED"/&gt;
              &lt;action android:name="android.intent.action.PACKAGE_ADDED"/&gt;
              &lt;data android:scheme="package"/&gt;
          &lt;/intent-filter&gt;
  </code></pre>
  
  <p></p>
  
  <p>the occurred is that when i use other actions its work in both ways.</p>
  
  <p>for example if i replace the filter on the example to this filter</p>
  
  <pre><code>IntentFilter filter = new IntentFilter(Intent.ACTION_SCREEN_ON);
  </code></pre>
  
  <p>the receiver works fine and get called when the screen is on</p>
  
  <p>are they 2 kinds of action:
   1) need to be declared on manifest
   2) don't need to be declared on manifest</p>