title: Start Broadcast Receiver from an activity in android
body: <p>I would like to start a broadcast receiver from an activity. I have a Second.java file which extends a broadcast receiver and a Main.java file from which I have to initiate the broadcast receiver. 
  I also tried doing everything in Main.java as follows but didn't know how to define in manifest file... </p>
  
  <h2>Main.java:</h2>
  
  <pre><code>public class Main extends Activity {
  /** Called when the activity is first created. */
    public void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      setContentView(R.layout.main);
  String rec_data = "Nothing Received";
  private BroadcastReceiver myReceiver = new BroadcastReceiver() {
  
          public void onReceive(Context context, Intent intent) {
              // TODO Auto-generated method stub
              if( intent.getStringExtra("send_data")!=null)
                      rec_data = intent.getStringExtra("send_data");
              Log.d("Received Msg : ",rec_data);
          }
      }; 
      }
      protected void onResume() {
          IntentFilter intentFilter = new IntentFilter();
          //intentFilter.addDataType(String);
          registerReceiver(myReceiver, intentFilter);
          super.onResume();
      }
  
    @Override
  protected void onPause() {
  // TODO Auto-generated method stub
      super.onPause();
      this.unregisterReceiver(this.myReceiver);
  }
  
  }
  </code></pre>
  
  <p>If I cannot do everything in one class as above, how can I call the Broadcast Receiver from Main.java? Can anyone please let me know where I'm doing it wrong? Thanks!</p>