title: android BroadcastReceiver not working as intended
body: <p>as far as I can tell this should work. Except it doesn't :-/ </p>
  
  <p>the idea is to extend all the Activity classes I use to include a BroadcastReceiver that pops up Toast Messages when I send them. The end game for this strategy is that async worker jobs can "discover for themselves" which is the "top most" form (if available) and then post messages to the uses via toast despite being part of a async event when <strong>I DO NOT CHOOSE(*)</strong> to pass the context as an argument.</p>
  
  <blockquote>
    <p>The problem: when I call doDemo() the fire event happenes (I get the
    <code>log.d</code> from doDemo()) but the receive event never fires.</p>
  </blockquote>
  
  <p><strong>(*)this is essential, it's the whole purpose</strong></p>
  
  <pre><code>public class ToastActivity extends Activity{
      private BroadcastReceiver ToastBroadCastReceiver = new BroadcastReceiver() {
          @Override
          public void onReceive( Context context, Intent intent ) {
              Toast.makeText(getApplicationContext(), intent.getAction() + " package: "+ intent.getPackage(), Toast.LENGTH_SHORT).show();
              Log.d("ToastBroadCastReceiver", "Broadcastreceiver: " + intent.getAction() + " package: "+ intent.getPackage() + " @" + System.currentTimeMillis());
          }
      };
  
      public void onResume() {
          super.onResume();
          registerReceiver(ToastBroadCastReceiver, new IntentFilter("com.my.domain.BROADCAST"));
      }
  
      public void onPause() {
          super.onPause();
          unregisterReceiver(ToastBroadCastReceiver);
      }
  
      public void doDemo(){
          Log.d("ToastBroadCastReceiver", "doDemo Broadcast started" );
          Intent broadCastIntent = new Intent();
          broadCastIntent.setAction( "com.my.domain.BROADCAST");
          broadCastIntent.setPackage( "well hello test!" );        
          sendBroadcast(broadCastIntent);
          Log.d("ToastBroadCastReceiver", "doDemo Broadcast sent" );
      }
  
  }
  </code></pre>
  
  <p><strong>EDIT</strong></p>
  
  <p>After a long conversation with Ali this is what we came up with</p>
  
  <pre><code>public class ToastActivity extends Activity{
      private BroadcastReceiver ToastBroadCastReceiver = new BroadcastReceiver() {
          @Override
          public void onReceive( Context context, Intent intent ) {
  
              if (intent.getAction().equals("TOASTMESSAGE")) {
                  String message = "";
                  Bundle extras = intent.getExtras();
                  if (extras != null)            {
                      message = extras.getString("message");
                  }
                  Toast.makeText(getApplicationContext(), message, Toast.LENGTH_SHORT).show();
                  Log.d("ToastBroadCastReceiver", "Broadcastreceiver: " + message + "|" + intent.getAction());
              }
          }
      };
  
      public void ToastRegister(){
          registerReceiver(ToastBroadCastReceiver, new IntentFilter("TOASTMESSAGE"));
      }
  
      public void ToastDeRegister(){
          try { 
              unregisterReceiver(ToastBroadCastReceiver);     
          } 
          catch (Exception e) {
              Log.e("ToastBroadCastReceiver", e.getMessage());
          }       
      }
  
      public void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          ToastRegister();
      }
  
      public void onResume() {
          super.onResume();
          ToastRegister();
      }
  
      public void onPause() {
          super.onPause();
          ToastDeRegister();
      }
  
      public void onDestroy() {
          super.onDestroy();
          ToastDeRegister();
      }
  
      public void doDemo(){
          Log.d("ToastBroadCastReceiver", "doDemo Broadcast started" );
  
          Intent broadCastIntent = new Intent();
          broadCastIntent.setAction("TOASTMESSAGE");
          broadCastIntent.putExtra("message","hello test message!");
          sendBroadcast(broadCastIntent);
  
          Log.d("ToastBroadCastReceiver", "doDemo Broadcast sent" );
      }
  
  }
  </code></pre>