title: Calling a method of an Activity from BroadCastReceiver class without creating the activity instance
body: <p>I want to do the exact same thing mentioned in the question in the following link <a href="https://stackoverflow.com/questions/16934425/call-an-activity-method-from-a-broadcastreceiver-class">Call an activity method from a BroadcastReceiver class</a>. But solution given there is not working for me and I can't comment there as I don't have enough reputation. I did everything mentioned in the solution but my broadcast receiver is not working with that code.</p>
  
  <p>I just want to call the method in the activity on receiving the broadcast request without creating an instance of the activity. Can it be done?</p>
  
  <p><b>EDIT:</b> Now I am adding the code.<br></p>
  
  <blockquote>
    <p><strong>Here is my MainActivity class</strong></p>
  </blockquote>
  
  <pre><code>public class MainActivity extends Activity {
  
      public static final String TAG="App1";
      private ActionReceiver receiver = null;
  
      //private YourBroadcastReceiverClassName yourBR = null;
  
      @Override
      protected void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.activity_main);
  
          // receiver= new ActionReceiver();
          //IntentFilter filter = new IntentFilter();
          //filter.addAction("com.example.app1.printSomething");
  
          // printSomething();
  
      }
  
      public void printSomething(){
          Toast.makeText(this,"Hello World",Toast.LENGTH_LONG);
      }
  
  
      @Override
      public boolean onCreateOptionsMenu(Menu menu) {
          // Inflate the menu; this adds items to the action bar if it is present.
          getMenuInflater().inflate(R.menu.main, menu);
          return true;
      }
  
    }
  </code></pre>
  
  <blockquote>
    <p><strong>This is my ActionReceiver class which is BroadcastReceiver</strong></p>
  </blockquote>
  
  <pre><code>public class ActionReceiver extends BroadcastReceiver{
  
      @Override
      public void onReceive(Context context, Intent intent) {
          if("com.example.app1.printSomething".equalsIgnoreCase(intent.getAction()))
              Toast.makeText(context,"Hello World", Toast.LENGTH_LONG).show();
      }
  }
  </code></pre>
  
  <blockquote>
    <p><strong>This is my <code>AndroidManifest.xml</code> file:</strong></p>
  </blockquote>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;manifest xmlns:android="http://schemas.android.com/apk/res/android"
      package="com.example.app1"
      android:versionCode="1"
      android:versionName="1.0" &gt;
  
      &lt;uses-sdk
          android:minSdkVersion="7"
          android:targetSdkVersion="16" /&gt;
  
      &lt;application
          android:allowBackup="true"
          android:icon="@drawable/ic_launcher"
          android:label="@string/app_name"
          android:theme="@style/AppTheme" &gt;
          &lt;activity
              android:name="com.example.app1.MainActivity"
              android:label="@string/app_name" &gt;
              &lt;intent-filter&gt;
                  &lt;action android:name="android.intent.action.MAIN" /&gt;
  
                  &lt;category android:name="android.intent.category.LAUNCHER" /&gt;
              &lt;/intent-filter&gt;
  
          &lt;/activity&gt;
          &lt;receiver android:name=".ActionReceiver"&gt;
              &lt;intent-filter&gt;
                  &lt;action android:name="com.example.app1.printSomething"/&gt;
              &lt;/intent-filter&gt;
          &lt;/receiver&gt;
      &lt;/application&gt;
  
  &lt;/manifest&gt;
  </code></pre>
  
  <p>Now, I want to call <code>printSomething()</code> Method written in <code>MainActivity</code> from <code>onReceive()</code> in  <code>ActionReceiver</code> class. But I don't want to launch <code>MainActivity</code> for that. Can it be done?</p>