title: How to access MainActivity from broadcastReceiver callback
body: <p>I am new to Android development and managed to get this far reading questions and answers on StackOverflow. Thank you everyone.</p>
  
  <p>I came up with a problem that I just can't figure out. I have seen similar problems posted but the answers are not clear to me. Please help me on this one.</p>
  
  <p>I want to call a method on my main activity from another class. The app crashes when I try to call the method. Here is the code:</p>
  
  <p>On the class file:</p>
  
  <pre><code>public class AlarmReceiver extends BroadcastReceiver {
      @Override
      public void onReceive(Context context, Intent intent) {
          MainActivity MainActivity = new MainActivity();
          MainActivity.ligaInternet();
      }
  }
  </code></pre>
  
  <p>On the mainactivity file:</p>
  
  <pre><code>protected void ligaInternet() {
      ConnectivityManager connMgr = (ConnectivityManager)
            getSystemService(Context.CONNECTIVITY_SERVICE);
      NetworkInfo networkInfo = connMgr.getActiveNetworkInfo();
      if (networkInfo != null &amp;&amp; networkInfo.isConnected()) {
          String urlText="http://www.regiprof.com/regiprof_sms.php";
          String stringUrl = urlText.toString();
          new DownloadWebpageTask().execute(stringUrl);
      } 
  }
  </code></pre>
  
  <p>How can I call the <code>ligaInternet()</code> function?</p>