title: Calling a Activity method from BroadcastReceiver in Android
body: <p>Here I am creating an online application that depends only on Internet.</p>
  
  <p>So whenever there is a network error it must notify user. For that, I have created a BroadcastReciver that receives call when network connection gets lost(Internet).</p>
  
  <p>All this works perfectly. Now what I need is that I have to call a method of Activity from this Broadcast Receiver, where I have created an Alert Dialogue.</p>
  
  <p>I have read many answers on stack-overflow.com that I can declare that method static and call by using only Activity name,</p>
  
  <p>e.g <code>MyActivityName.myMethod()</code></p>
  
  <p>But I can't declare my method static, because I am using Alert Dialogue there and it shows me error on line,</p>
  
  <pre><code>AlertDialog.Builder alertDialog = new AlertDialog.Builder(this);
  </code></pre>
  
  <p>that <strong>Cannot use this in a static context</strong>.</p>
  
  <p>So, how can I call a method of Activity(must not static and without starting that activity) from a Broadcast Receiver ?</p>
  
  <p>And can I get Activity(or fragment) name from Broadcast Receiver which is currently running? </p>